nilkash
nilkash

Reputation: 7536

Get distance filtered nearby places using google places api

Hi I am developing small android application in which I am displaying nearby places using google places api. I tried with following request :

 https://maps.googleapis.com/maps/api/place/nearbysearch/json?rankBy=distance&radius=5000&location=19.107991%2C73.001277&key=API_KEY_VAL&type=school

So above request returns nearby schools but those are not distance sorted. I tried with another request :

https://maps.googleapis.com/maps/api/place/nearbysearch/json?rankby=distance&location=19.107991%2C73.001277&key=API_KEY_VAL&type=school

Above request gives me distance sorted result but I can not use radius paramter in that case.

Also I am facing some chanllenges in both request. In the first request it returns me some schools within 5Km redious. In the second request it returns me nearby schools. If I check the both result some of the nearby schools are not present in the request which has radius as param.

My expected output needs nearby school within 5Km radius with distance sorted. Am doing anything wrong in above requests? Need some help. Thank you.

Upvotes: 0

Views: 3632

Answers (1)

xomena
xomena

Reputation: 32138

The documentation is very clear regarding the rankby and radius parameters:

radius — Defines the distance (in meters) within which to return place results. The maximum allowed radius is 50 000 meters. Note that radius must not be included if rankby=distance (described under Optional parameters below) is specified.

rankby — Specifies the order in which results are listed. Note that rankby must not be included if radius (described under Required parameters above) is specified.

https://developers.google.com/places/web-service/search#PlaceSearchRequests

So there is no way to use radius parameter in conjunction with rankby=distance.

The first request in your examples ignores rankBy (it's also case sensitive), so you are getting prominent results within 5 km radius. The less prominent, but close results might be omitted in this case.

The workaround might be getting results ordered by distance and filter out all places where distance between the location and the place coordinate is greater than 5000 meters.

Upvotes: 1

Related Questions