Created
December 27, 2015 18:05
-
-
Save beck03076/fe031ac598a3cbbdd886 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function initializeAutocomplete(){ | |
var input = document.getElementById('product_f_locality'); | |
var options = { | |
types: ['(regions)'], | |
componentRestrictions: {country: "IN"} | |
}; | |
var autocomplete = new google.maps.places.Autocomplete(input, options); | |
google.maps.event.addListener(autocomplete, 'place_changed', function() { | |
var place = autocomplete.getPlace(); | |
var lat = place.geometry.location.lat(); | |
var lng = place.geometry.location.lng(); | |
var placeId = place.place_id; | |
// to set city name, using the locality param | |
var componentForm = { | |
locality: 'short_name', | |
}; | |
for (var i = 0; i < place.address_components.length; i++) { | |
var addressType = place.address_components[i].types[0]; | |
if (componentForm[addressType]) { | |
var val = place.address_components[i][componentForm[addressType]]; | |
document.getElementById("product_f_city").value = val; | |
} | |
} | |
$('#product_latitude').val(lat) | |
$('#product_longitude').val(lng) | |
$('#product_f_google_place_id').val(placeId); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment