Problem with Geocoding in specified region

184 views
Skip to first unread message

Max Pain

unread,
Jan 22, 2010, 5:09:48 AM1/22/10
to Google Maps JavaScript API v3
I've got a problem with API v3 geocoding in specified region.
First I set the "region" option in request to "ru", but still was
getting objects in other countries.
Then I tried to set search location via bounds, but it didn't work
too.
My JS:

var g = new google.maps.Geocoder();
var ne = new google.maps.LatLng(55.970724,37.922058);
var sw = new google.maps.LatLng(55.545727,37.382355);
var ba = new google.maps.LatLngBounds(sw, ne);

var str = document.getElementById('place').value;
var d = document.getElementById('answer');

g.geocode({address: str, language: 'ru', region: 'ru', bounds: ba},
function (results, status) {
for (var i in results) {
var p = document.createElement('p');
p.innerHTML = results[i].formatted_address;
d.appendChild(p);
}
});

What am I doing wrong?

Esa

unread,
Jan 22, 2010, 10:51:26 AM1/22/10
to Google Maps JavaScript API v3
The 'region' attribute does not restrict the results in the region but
the results are *biased* by the region.
http://code.google.com/apis/maps/documentation/v3/services.html#RegionCodes

If you want results from one country only, the most robust solution is
to concatenate the country name to the request.

query += " ru";

You can also parse the country code from the response and accept/
discard a result by that. It is a bit tricky with the structure of V3
geocode response object.
http://koti.mbnet.fi/ojalesa/geocode/prettygeocode_v3.htm

Reply all
Reply to author
Forward
0 new messages