Reputation: 637
When using Googles geocoder service to display a city on a map; filling out a non-existing city results in an error.
Is there a way to display some suggestions based on the filled out city?
var geocoder = new GClientGeocoder();
function showAddress(address, zoom) {
geocoder.getLatLng(
address,
function(point) {
if (!point) {
//no point found....
//Suggest some points :)
} else {
map.setCenter(point, zoom);
}
}
);
}
showAddress('Someplace, Nederland', 14);
Upvotes: 1
Views: 587
Reputation: 2063
Suggestions are returned in the Placemarks attribute of the results. I'm using v3 and this works, try calling this with address="Washington Blvd"
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/>');
}
}
}
});
}
Upvotes: 1
Reputation: 344301
If you are simply geocoding cities, you may want to consider starting to build your own cities-to-coordinates cache.
This is one approach that you may want to consider:
With this approach you can also seed your cache, in such a way to resolve city names which you are already aware that Google is not able to geocode.
Upvotes: 0
Reputation: 73484
If it finds a match it will return the matches as Addresses and those are the suggestions. It shouldn't return an error, it should just return an empty list if it finds no matches. Can you post the code?
Upvotes: 0