Skip to content

Instantly share code, notes, and snippets.

@Faizanq
Created January 13, 2019 17:33
Show Gist options
  • Save Faizanq/fad8dc0fd7f49ed4ba66df86ba588fd2 to your computer and use it in GitHub Desktop.
Save Faizanq/fad8dc0fd7f49ed4ba66df86ba588fd2 to your computer and use it in GitHub Desktop.
<script src="http://maps.googleapis.com/maps/api/js?libraries=places" type="text/javascript"></script>
<script type="text/javascript">
function initialize() {
var input = document.getElementById('searchTextField');
var autocomplete = new google.maps.places.Autocomplete(input);
google.maps.event.addListener(autocomplete, 'place_changed', function () {
var place = autocomplete.getPlace();
document.getElementById('city2').value = place.name;
document.getElementById('cityLat').value = place.geometry.location.lat();
document.getElementById('cityLng').value = place.geometry.location.lng();
//alert("This function is working!");
//alert(place.name);
// alert(place.address_components[0].long_name);
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment