Gabotronix
1 month ago
137
0
General

Avoid Google Places API expanding boundaries

Posted 1 month ago by Gabotronix

Hi everybody, I'm using goole places javascript API to search for establishements inside a boundary, sometimes google places will expand its search radius and I want to avoid this behaviour, is this possible?

My search query has a bounds filed (a pair of lat-lng coordinates) where I want google places to search ONLY inside this boundary... is there like a flag or something to avoid this behaviour?

search()
    {
        const self = this;

        var bounds = new google.maps.LatLngBounds(
            new google.maps.LatLng(36.715289, -4.423523),
            new google.maps.LatLng(36.717387, -4.422407)
        );

        self.placesService = new google.maps.places.PlacesService(self.map);
        
        //var request = { placeId: 'ChIJN1t_tDeuEmsRUsoyG83frY4', fields: ['name', 'rating', 'formatted_phone_number', 'geometry']};
        var request = { bounds: bounds, types: ['restaurant', 'bakery', 'cafe', 'food', 'meal_takeaway', 'bar', 'meal_delivery'] };

        //const request = {query: "Restaurants in Malaga",fields: ["name", "geometry"]};

        self.placesService.search(request, self.placesCallback);
        //self.placesService.findPlaceFromQuery(request, self.placesCallback);
        //places.getDetail
        
    },

Please sign in or create an account to participate in this conversation.