Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Region Biasing in Jquery Scripting

I can't seem to get this right at the moment, Google talks about region basing here:

https://developers.google.com/maps/documentation/geocoding/#RegionCodes

It uses the following parameter:

region:

This is the code im working with: http://jsfiddle.net/spadez/Jfdbz/19/

My question is how do I pass my variable "ctryiso" to this parameter in my script? When I try, nothing changes, so when ctryiso is set to US and I type in London it still geocodes London, England. I've heard it may be a bit unreliable but still I don't think my implementation is correct.

like image 797
Jimmy Avatar asked Jun 22 '13 19:06

Jimmy


1 Answers

Normally where you have:

geocoder.geocode({
    address: query
}

You should pass region just like that (as you already mentioned):

geocoder.geocode({
    address: query,
    region: SOME_VARIABLE_WITH_REGION_CODE
}

And it should work, although... it seems it isn't and more people are having the same problem.

The (ugly) solution is to add it to address, like this:

geocoder.geocode({
    address: query + ', ' + SOME_VARIABLE_WITH_REGION_CODE
}

I've just tested it and it works, but as i said - it's not the "nice" neither correct way to do it - it's just workaround.

As we can see here: https://developers.google.com/maps/documentation/javascript/reference?hl=th-TH&csw=1#GeocoderRequest

You can pass address, bounds, location and region. Since region doesn't seems to be working, i'd try to use bounds by first getting coordinates for desired region:

https://developers.google.com/maps/documentation/javascript/reference?hl=th-TH&csw=1#LatLngBounds

like image 61
Michał Prajsnar Avatar answered Nov 06 '22 09:11

Michał Prajsnar