I want to get all the airport near my location order by distance. I am using Nearby Search Requests with google places api using this url : https://maps.googleapis.com/maps/api/place/nearbysearch/xml?location=51.9143924,-0.1640153&sensor=true&key=api_key&radius=50000&types=airport The results that I am getting are sparse with no order what so ever. I tried rankby=distance but no result appear.
and as per https://developers.google.com/places/documentation/search#PlaceSearchRequests documentation " radius must not be included if rankby=distance".
Google-maps – How to sort results by distance with google places api using Nearby Search Requests
apigoogle mapsgoogle-placesgoogle-places-api
Best Answer
Yes, you cannot use radius and rankBy in same request. But you can use
rankBy=distance
and then count distance youself based ongeometry.location.lat
andgeometry.location.lng
. For exmaple in groovy i've done like that:GeoPosition
andPlace
classes are implemented by me, so don't expect to find them at the core libs :)where distance is counted like that (Haversine formula):