So my issue is that the results are spitting out as:
1980 Mission Street, San Francisco, CA, United States
...but I need it to give me the zipcode because when I put it back into google's Geocoder, for some reason it doesn't register the location.
// This is the code I have just the autocomplete input field
var input = document.getElementById('id_address');
var options = {
types: ['address'],
componentRestrictions: {country:'us'}
};
autocomplete = new google.maps.places.Autocomplete(input, options);
// This is how I'm using the geocoder
window.onload = function initMap() {
console.log("{{ task.address }}");
console.log("{{ location }}");
var address = "{{ location }}";
geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'address': address }, function(results, status) {
<!-- console.log(address); -->
if (status == google.maps.GeocoderStatus.OK) {
var map = new google.maps.Map(document.getElementById('map'), {
center: results[0].geometry.location,
zoom: 12,
});
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location,
});
}
});
}
I have a working solution, but the user will have to input each piece of the address separately. I'm trying to change it so they can just fill out one input field and then I can spit that address into the gecoder.geocode().
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…