1
votes

Here is my string I'm passing to the geocoder service.

http://maps.googleapis.com/maps/api/geocode/xml?sensor=false&address=Lindon&region=GB&componentRestrictions=locality

where region=GB is country code for United Kingdom and instead of London I'm passing in Lindon. Componentrestrictions=locality should be for cities only!

But my results are coming back with some location in the USA!!

Is this not how you use component restrictions for google geocoder?

I don't want to see any results here if 'Lindon' is passed in, especially not for the USA.

2

2 Answers

0
votes

Add ",GB" for address parameter.

http://maps.googleapis.com/maps/api/geocode/xml?sensor=false&address=Lindon,UK&region=GB&componentRestrictions=locality&language=en enter image description here

The region parameter is just "biasing", not restricted the area. https://developers.google.com/maps/documentation/javascript/geocoding#GeocodingRegionCodes

In my experience, adding country code, zip code, works for all most cases.

0
votes
  1. there is no parameter componentRestrictions(this parameter belongs to the Javascript-API), the parameter for the Webservice is called components
  2. a component must have a name(e.g. locality) and a value. In your case, when you want to search for a city called Lindon it should be locality:Lindon
  3. the region-parameter doesn't restrict the results, it will only prefer results from the given region. Use the component country:gb when you want to restrict the results to GB.

Sample-request for a city Washington (as it seems there is no city Lindon in the UK)

http://maps.googleapis.com/maps/api/geocode/xml?components=locality:Washington|country:gb