Courchevel, Saint-Bon-Tarentaise, France
appears in the results but when I want to use this address geocode
doesn't recognize it.
It recognizes only this one Courchevel 1650, Saint-Bon-Tarentaise, France
.
How do I make the original address recongizable?
var placeSearch, autocomplete, destination;
var componentForm = {
street_number: 'short_name',
route: 'long_name',
locality: 'long_name',
administrative_area_level_1: 'short_name',
country: 'long_name',
postal_code: 'short_name'
};
function initAutocomplete() {
// Create the autocomplete object, restricting the search to geographical
// location types.
autocomplete = new google.maps.places.Autocomplete(
/** @type {!HTMLInputElement} */
(document.getElementById('from')), {
types: ['geocode']
}
);
// When the user selects an address from the dropdown, populate the address
// fields in the form.
autocomplete.addListener('place_changed', fillInAddress);
destination = new google.maps.places.Autocomplete(
/** @type {!HTMLInputElement} */
(document.getElementById('to')), {
types: ['geocode']
}
);
// When the user selects an address from the dropdown, populate the address
// fields in the form.
destination.addListener('place_changed', fillInAddressDestination);
}
// [START region_fillform]
function fillInAddress() {
var place = autocomplete.getPlace();
for (var component in componentForm) {
document.getElementById(component).value = '';
document.getElementById(component).disabled = false;
}
// Get each component of the address from the place details
// and fill the corresponding field on the form.
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(addressType).value = val;
}
}
}
// [END region_fillform]
I've been trying to reproduce the issue, testing those two addresses on the Google Autocomplete Address Form and the Place Autocomplete. It seems like Google is trying to place your search somewhere and is just putting it in the general "Courchevel region."
It seems there is not a proper way to fix this using the Google API, except for using more precise addresses or by reporting the address issue to Google and waiting for them to fix the API. (I think they actually respond quickly to these.)
I tried to verify the address using SmartyStreets. It matched your address to this, and I'm not sure if it's correct:
I would suggest using an address API, like SmartyStreets, that does verification (meaning, it checks against address data to find a known address and pinpoint it rather than just trying to pinpoint all search terms as they are entered; it's especially handy if the address is more important to you than the map or if you're doing shipping or something like that).
Full disclosure: I worked for SmartyStreets.