I am trying to call Google map api where it will auto complete address in location field. Now, I have 2 location field where I want to auto field it.
I have wrote following JavaScript code.
var options = {
componentRestrictions: { country: 'usa' }
};
google.maps.event.addDomListener(window, 'load', function () {
if (document.getElementById("address")) {
var places = new google.maps.places.Autocomplete(document.getElementById('address'), options);
google.maps.event.addListener(places, 'place_changed', function () {
var place = places.getPlace();
var address = place.formatted_address;
var latitude = place.geometry.location.lat();
var longitude = place.geometry.location.lng();
document.getElementById("Latitude").value = latitude;
document.getElementById("Longitude").value = longitude;
});
}
if (document.getElementById("addressModal")) {
var placesModal = new google.maps.places.Autocomplete(document.getElementById('addressModal'), options);
google.maps.event.addListener(placesModal, 'place_changed', function () {
var placeModal = placesModal.getPlace();
var latitudeModal = placeModal.geometry.location.lat();
var longitudeModal = placeModal.geometry.location.lng();
document.getElementById("Latitude").value = latitudeModal;
document.getElementById("Longitude").value = longitudeModal;
});
}});
It is auto completing for 1st location field (id = address) but it is not working for 2nd location field (id = addressModal) Please help. Thanks in advance.