Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var searchBox;
- var changebtn = document.getElementById('changebtn');
- // create a new geocoder object
- geocoder = new google.maps.Geocoder();
- // add event listener
- changebtn.addEventListener('click', assignLocation);
- // Set the bounds
- var defaultBounds = new google.maps.LatLngBounds(
- new google.maps.LatLng(-33.8902, 151.1759),
- new google.maps.LatLng(-33.8474, 151.2631));
- // This autocomplete is for use in the search within time entry box.
- searchBox = new google.maps.places.Autocomplete(
- document.getElementById('new_location'), defaultBounds);
- }
- // geocodes the address and directs the page to the server end
- function assignLocation () {
- var new_location = document.getElementById('new_location').value;
- var lat, lng;
- geocoder.geocode({'address' : new_location}, function (results, status) {
- // checks if the returned result is ok
- if ( status === 'OK' ) {
- if ( results[0] ) {
- // assign the latlng values
- lat = results[0].geometry.location.lat;
- lng = results[0].geometry.location.lng;
- }
- else
- alert ("No results found");
- }
- else {
- alert("Error: " + status);
- }
- alert("lat: "+lat+" lng: "+lng);
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement