google maps javascript api v3 places库不返回任何边界结果 [英] google maps javascript api v3 places library doesn't return any results for the bounds

查看:62
本文介绍了google maps javascript api v3 places库不返回任何边界结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Places库通过LatLngBounds类在两个坐标之间显示标记.如果我在地点搜索请求中注释掉name属性(即星巴克),则可以看到一些标记.有人可以为我提供以下指导:

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)目前,我看到的标记位于两个坐标的中间,并且没有沿我假设的边界均匀分布,这会创建一个矩形,您必须在其中看到它们.我认为这些标记只是针对中心计算的.

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)当我提供属性名称"和值星巴克"时,我在地图上看不到任何标记.

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

我认为我的bounds对象很好,因为在调试时,我可以看到其中的西北坐标和西南坐标.坐标是

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

  • 34.0522342,-118.2436849-加利福尼亚洛杉矶
  • 33.7489954,-84.3879824-乔治亚州亚特兰大

有人可以指导我我要去哪里哪里

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
        });
    }

推荐答案

您的边界是一个非常狭窄的矩形,在洛杉矶和亚特兰大之间延伸(不是我想的那样):

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

针对整个国家/地区的位置请求存在问题,您只会得到20条结果,看起来您可能是对的,因为它们以边界为中心,而且似乎没有足够的实际"星巴克被发现:

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

这篇关于google maps javascript api v3 places库不返回任何边界结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆