Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. var searchBox;
  2. var changebtn = document.getElementById('changebtn');
  3.  
  4. // create a new geocoder object
  5. geocoder = new google.maps.Geocoder();
  6.  
  7. // add event listener
  8. changebtn.addEventListener('click', assignLocation);
  9.  
  10. // Set the bounds
  11. var defaultBounds = new google.maps.LatLngBounds(
  12. new google.maps.LatLng(-33.8902, 151.1759),
  13. new google.maps.LatLng(-33.8474, 151.2631));
  14.  
  15. // This autocomplete is for use in the search within time entry box.
  16. searchBox = new google.maps.places.Autocomplete(
  17. document.getElementById('new_location'), defaultBounds);
  18.  
  19. }
  20.  
  21. // geocodes the address and directs the page to the server end
  22. function assignLocation () {
  23.  
  24.  
  25. var new_location = document.getElementById('new_location').value;
  26.  
  27. var lat, lng;
  28.  
  29. geocoder.geocode({'address' : new_location}, function (results, status) {
  30.  
  31. // checks if the returned result is ok
  32. if ( status === 'OK' ) {
  33.  
  34. if ( results[0] ) {
  35.  
  36. // assign the latlng values
  37. lat = results[0].geometry.location.lat;
  38. lng = results[0].geometry.location.lng;
  39.  
  40. }
  41. else
  42. alert ("No results found");
  43. }
  44. else {
  45. alert("Error: " + status);
  46. }
  47.  
  48. alert("lat: "+lat+" lng: "+lng);
  49.  
  50. });
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement