luckysing_noobster
luckysing_noobster

Reputation: 1993

google maps javascript api v3 places library doesn't return any results for the bounds

I am trying to use the places library to display markers between two coordinates using the LatLngBounds class. I am able to see a few markers if I comment out the name attribute which is starbucks in the places search request.Can someone please guide me with the following:

1) Currently the markers I see are in the middle of the two coordinates and not evenly distributed along the bounds which I assume creates a rectangle in which you must see them. I think the markers are just being calculated for the the center.

2) When I provide the attribute 'name' and the value "starbucks" I do not see any markers on the map.

I think my bounds object is fine because when I debug I am able to see the northwest and southwest coordinates inside. The coordinates are

Can someone guide me where I am going wrong.

   function useCordinates(){
        ...
       var defaultBounds = new google.maps.LatLngBounds();

    var places = []; 
    places.push(new google.maps.LatLng(latLongSrc[0],latLongSrc[1]));
    places.push(new google.maps.LatLng(latLongDest[0],latLongDest[1]));

        defaultBounds.extend(places[0]);
        defaultBounds.extend(places[1]);

    //var center = defaultBounds.getCenter(); 
        //defaultBounds.contains(center);

         var request = {
                    //attribute to be commented
        name:"starbucks",
       bounds: defaultBounds,
       types:['establishment']


      };

      service = new google.maps.places.PlacesService(map);
      service.search(request, callback);
    }

     function callback(results, status) {
      if (status == google.maps.places.PlacesServiceStatus.OK) {
        for (var i = 0; i < results.length; i++) {
          var place = results[i];
          createMarker(results[i]);
        }
      }
         }
         function createMarker(place) {
        var placeLoc = place.geometry.location;
        var marker = new google.maps.Marker({
          map: map,
          position: place.geometry.location
        });
    }

Upvotes: 0

Views: 448

Answers (1)

geocodezip
geocodezip

Reputation: 161324

Your bounds is a very narrow rectangle that stretches between Los Angeles and Atlanta (not I think what you want):

http://www.geocodezip.com/v3_GoogleEx_place-search_starbucks.html

Places requests which target the whole country are problematic, you only get 20 results, looks like you might be correct that they are centered on the bounds, and there don't seem to be any "real" starbucks close enough to there to be found:

http://www.geocodezip.com/v3_GoogleEx_place-search_starbucks2.html

If you search in Seattle, WA however, you get some:

http://www.geocodezip.com/v3_GoogleEx_place-search_starbucks3.html

Upvotes: 2

Related Questions