【问题标题】:Places API textSearch vs nearbySearchPlaces API 文本搜索与附近搜索
【发布时间】:2013-11-02 16:05:33
【问题描述】:

这里我有一个演示,它使用nearbySearch 搜索框内的对象(路由拳击手实用程序):

http://www.geocodezip.com/v3_SO_RouteBoxerPlaces.html 代码:

function findPlaces(boxes,searchIndex) {
   var request = {
       bounds: boxes[searchIndex],
       types: ["gas_station"]
   };
   // alert(request.bounds);
   service.radarSearch(request, function (results, status) {
   if (status != google.maps.places.PlacesServiceStatus.OK) {
     alert("Request["+searchIndex+"] failed: "+status);
     return;
   }
   // alert(results.length);
   document.getElementById('side_bar').innerHTML += "bounds["+searchIndex+"] returns "+results.length+" results<br>"
   for (var i = 0, result; result = results[i]; i++) {
     var marker = createMarker(result);
   }
   searchIndex++;
   if (searchIndex < boxes.length) 
     findPlaces(boxes,searchIndex);
   });
}

现在,当我尝试使用 textSearch 而不是 nearbySearch 时,我看到带有 textSearch 和查询搜索框外对象的代码...http://jsbin.com/ifUZIti/1/edit

function findPlaces(boxes,searchIndex) {
   var request = {
       bounds: boxes[searchIndex],
       query: 'gas station'
   };
   // alert(request.bounds);
   service.textSearch(request, function (results, status) {
   if (status != google.maps.places.PlacesServiceStatus.OK) {
     alert("Request["+searchIndex+"] failed: "+status);
     return;
   }
   // alert(results.length);
   document.getElementById('side_bar').innerHTML += "bounds["+searchIndex+"] returns "+results.length+" results<br>"
   for (var i = 0, result; result = results[i]; i++) {
     var marker = createMarker(result);
   }
   searchIndex++;
   if (searchIndex < boxes.length) 
     findPlaces(boxes,searchIndex);
   });
}

textSearch 和 nearbySearch 之间有什么区别,为什么当我尝试使用 textSearch 代码搜索并在定义的框外查找对象时?这里有什么问题? 使用nearbySearch 一切正常,但我不能在附近搜索中使用查询,所以我必须使用 textSearch 但在框外使用textSearch 脚本搜索对象? 我该如何解决这个问题?

【问题讨论】:

    标签: javascript google-maps google-places-api bounding-box


    【解决方案1】:

    如果您在高级渲染中放大看起来像是在框外的地方,您会看到它们要么都在框内,要么就在框外。它并不像乍一看那么糟糕。请参阅my version of your code 以查看结果。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多