放置 API 文本搜索与附近搜索

Places API textSearch vs nearbySearch

本文关键字:附近搜索 搜索 文本 API 放置      更新时间:2023-09-26

在这里,我有一个演示,它使用nearbySearch来搜索框中的对象(route boxer实用程序):

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时,我看到带有文本搜索和查询的代码搜索框外的对象......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);
   });
}
什么是

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

如果在高级渲染中放大看起来远离框外的位置,您将看到它们要么都在框内,要么就在框外。它并不像乍一看那么糟糕。请参阅我的代码版本以查看结果。