Return list of possible address matches from google?
I am trying to add functionality to a web app of mine that allows a user to enter an address estimation, for example "McDonalds, Detroit, MI", and then select the exact address from a list of possible matches.
I am already familiar wi开发者_运维百科th direct geocoding (address -> lat, lng) and reverse geocoding (lat, lng -> address). Does anyone know how I can accomplish the above using just the google geocoding API?
Thanks!
When you geocode the address google returns a list of possible matches in the response
A geocode request for main st returns 2 results in new york, 1 in utah, 1 in maine, etc...
You just parse the response to get the different locations
You can't. Google's Geocoder will not match on business locations in the majority of cases. What you want is a combination of local search + geocoding, or a address suggest service, which Google's Geocoding service doesn't offer.
Galen is right, here's working code against V3 - I found the suggestions in the Placemarks attribute of the results. Try address = "Broad Street" in the below example.
if (geocoder) {
geocoder.getLocations(
address,
function (results) {
if (!results) {
alert(address + " no suggestions");
} else {
$('#output').html('');
if (results.Placemark) {
for (var i = 0; i < results.Placemark.length; i++) {
$('#output').append(i + ': ' + results.Placemark[i].address + '<br/>');
}
}
}
});
}
精彩评论