Advertisement
Guest User

Untitled

a guest
Aug 27th, 2016
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. {
  2. "results" : [
  3. {
  4. "address_components" : [
  5. {
  6. "long_name" : "Jabalpur",
  7. "short_name" : "Jabalpur",
  8. "types" : [ "locality", "political" ]
  9. },
  10. {
  11. "long_name" : "Jabalpur",
  12. "short_name" : "Jabalpur",
  13. "types" : [ "administrative_area_level_2", "political" ]
  14. },
  15. {
  16. "long_name" : "Madhya Pradesh",
  17. "short_name" : "MP",
  18. "types" : [ "administrative_area_level_1", "political" ]
  19. },
  20. {
  21. "long_name" : "India",
  22. "short_name" : "IN",
  23. "types" : [ "country", "political" ]
  24. },
  25. {
  26. "long_name" : "482001",
  27. "short_name" : "482001",
  28. "types" : [ "postal_code" ]
  29. }
  30. ],
  31. "formatted_address" : "Jabalpur, Madhya Pradesh 482001, India",
  32. "geometry" : {
  33. "bounds" : {
  34. "northeast" : {
  35. "lat" : 23.246354,
  36. "lng" : 80.08003219999999
  37. },
  38. "southwest" : {
  39. "lat" : 23.1050362,
  40. "lng" : 79.85747339999999
  41. }
  42. },
  43. "location" : {
  44. "lat" : 23.181467,
  45. "lng" : 79.98640709999999
  46. },
  47. "location_type" : "APPROXIMATE",
  48. "viewport" : {
  49. "northeast" : {
  50. "lat" : 23.246354,
  51. "lng" : 80.08003219999999
  52. },
  53. "southwest" : {
  54. "lat" : 23.1050362,
  55. "lng" : 79.85747339999999
  56. }
  57. }
  58. },
  59. "place_id" : "ChIJfam2DxqugTkRueNDvBYGAkQ",
  60. "types" : [ "locality", "political" ]
  61. }
  62. ],
  63. "status" : "OK"
  64. }
  65.  
  66. <!DOCTYPE html>
  67. <html lang="en">
  68. <head>
  69. <meta charset="UTF-8">
  70. <title>Geocode</title>
  71. </head>
  72. <body>
  73. Enter Address<input type="text" id="UserInput">
  74. Go<input type="button" onclick="geoCode()">
  75.  
  76. <script>
  77.  
  78. function geoCode(){
  79.  
  80. var UserInput = document.getElementById('UserInput').valueOf();
  81. var xmlhttp = new XMLHttpRequest();
  82. var ApiKey = 'AIzaSyDZP2E_5LLE6VOwIbrNImS32sAx5rsgEbU';
  83. var myArr;
  84.  
  85. var url = 'https://maps.googleapis.com/maps/api/geocode/json?address='+UserInput.value+'&key='+ApiKey;
  86.  
  87. var xhr = new XMLHttpRequest();
  88. xhr.open('GET',url,true);
  89. xhr.send();
  90.  
  91. xhr.onreadystatechange = processRequest;
  92.  
  93. function processRequest() {
  94. if(xhr.readyState==4 && xhr.status==200)
  95. {
  96. var response = JSON.parse(xhr.responseText);
  97. alert(response["results"][0][0]);
  98. }
  99. }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement