-1

I'm using Google's Geocoder API to reverse geocode the current nearby location. When I was looking for a place in my country, somehow I will be redirected to another location with the same name in another country?

Is it possible to get the location of nearby places first before directing me to other place?

alextanhongpin
  • 607
  • 1
  • 8
  • 11
  • Sure. Here you have a function to calculate the distance between two LatLng points: http://stackoverflow.com/questions/1502590/calculate-distance-between-two-points-in-google-maps-v3 . So you pass all the results through this function, store them in an array, then sort the array. (Could you post some code of what you made so far?) – Emmanuel Delay Jun 05 '15 at 11:22
  • 1
    [Reverse geocoding is the process of converting geographic coordinates into a human-readable address](https://developers.google.com/maps/documentation/javascript/geocoding#ReverseGeocoding). That doesn't sound like what you are asking about in your question (name shouldn't be involved with reverse geocoding). Are you asking about _normal_ geocoding? **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 or position the map. – geocodezip Jun 05 '15 at 11:48
  • I got the facts wrong, it should be geocoding - not reverse geocoding – alextanhongpin Jun 05 '15 at 18:05

1 Answers1

0

You may restrict the search to a specific country via the componentRestrictions-property.

Example:

{'address': 'Philadelphia',componentRestrictions:{country:'de'}}

...instead of Philadelphia in the US the geocoder will return a small village in Germany with the name "Philadelphia"

https://maps.googleapis.com/maps/api/geocode/json?address=Philadelphia&components=country:de

Dr.Molle
  • 116,463
  • 16
  • 195
  • 201
  • a useful link https://developers.google.com/maps/documentation/geocoding/#RegionCodes – alextanhongpin Jun 08 '15 at 02:29
  • note: the region-parameter doesn't restrict the results to the particular region, it only prefers results from the given region. e.g. for the link in my answer I didn't get the desired result with the region-parameter, I get Philadelphia in the US instead: https://maps.googleapis.com/maps/api/geocode/json?address=Philadelphia&region=de – Dr.Molle Jun 08 '15 at 02:48
  • yes, but the componentRestrictions does limit the search result to that particular country – alextanhongpin Jun 08 '15 at 03:04