Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: Is it possible for Google Places API to return one single object instead of an array of objects when querying?

user9269133:

I'm playing around with Google Places Api and I was wondering if it were possible to return just one closest result. In the example below I can return all the gyms within a 1km radius which is fine, but if I were to return the closest police station or hospital something for which I'd only want to know the closest one is there a way to do this. It seems the API is returning all the objects within a radius and it can't be altered. I can't seem to find any documentation that highlights this issue, and any attempts I've made still returns all the places in the area.


function GymReport(){

// Gets the latitude and longitude of a location searched by a user
$('.search_latitude').val(marker.getPosition().lat());
$('.search_longitude').val(marker.getPosition().lng());

var Lat = marker.getPosition().lat();
console.log(Lat);

var Long = marker.getPosition().lng();
console.log(Long);

var location = {lat: Lat, lng: Long};

var service = new google.maps.places.PlacesService(map);
service.nearbySearch({
location: location,
radius: 1000,
type: ['gym']
}, callback);
}

Callback Class


function callback(results, status) {

if (status === google.maps.places.PlacesServiceStatus.OK) {
if(marker)
marker.setMap(null)
for (var i = 0; i createMarker(results[i]); }
}
}



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered
HERE


This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: Is it possible for Google Places API to return one single object instead of an array of objects when querying?

×

Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription

×