I'm using the google geocoder with an option to only return results from Germany
Here's the relevant part of my function
...
var geocoder = new google.maps.Geocoder();
geocoder.geocode({"address":address,"region":"DE" }, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[0].geometry.location) {
completeGeo(results[0],address);
} else {
completeGeo(null,address);
}
...
but if i geocode "cuvry" too find that street in germany
google returns for example "Cuvry, France" which is outside of the region parameter
How can I prevent google geocoder from returning results that are not in a certain Country? I mean return, not check in callback if country-code is matching.
Get the most out of the tool by learning how to use it with real-life data During a period of time, the coordinates of this sport center in the north of Madrid was erroneously returned in about 3% of all our geocoding requests to Google’s Geocoding API. Source: Google Maps
Geocoding responses Geocoding responses are returned in the format indicated by the output flag within the URL request's path. In this example, the Geocoding API requests a json response for a query on "1600 Amphitheatre Parkway, Mountain View, CA". This request demonstrates using the JSON output flag:
After over a year of intense usage, we have found that the Google Geocoding service provides results of excellent quality. Nevertheless, working with real-life data, there were some things that caused us quite a headache until we figured them out, which is why we would like to share with you three things to avoid when using Google’s Geocoding API:
Geocoding is the process of converting addresses (like "1600 Amphitheatre Parkway, Mountain View, CA") into geographic coordinates (like latitude 37.423021 and longitude -122.083739), which you can use to place markers on a map, or position the map. Reverse geocoding is the process of converting geographic coordinates into a human-readable address.
This might work using component filters. "components":"country:DE"
var geocoder = new google.maps.Geocoder();
geocoder.geocode({"address":address, "componentRestrictions":{"country":"DE"} },
function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[0].geometry.location) {
completeGeo(results[0],address);
} else {
completeGeo(null,address);
}
});
When I changed it to
geocoder.geocode({"address":address, "componentRestrictions":{"country":"DE"} },
for germany my search results found vietnam.
I have changed it to this:
geocoder.geocode( {'address':address + ', Deutschland'}, function(results, status)
This works fine with countries name in own language.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With