1

ボックス内のオブジェクトを検索するために使用するデモがあります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 コード検索を使用して、定義されたボックスの外側のオブジェクトを検索しようとすると、 と とtextSearchの違いは何ですか? nearbySearchここで何が問題ですか?すべて正常に動作しnearbySearchますが、nearSearch でクエリを使用できないため、textSearch を使用する必要がありますが、textSearchボックスの外側のスクリプト検索オブジェクトを使用する必要がありますか? どうすればこれを解決できますか?

4

1 に答える 1

1

高レベルのレンダリングでボックスの外側にあるように見える場所を拡大すると、それらがすべてボックスの内側にあるか、ボックスのすぐ外側にあることがわかります。最初の赤面に見えるほど悪くはありません。結果を確認するには、コードの私のバージョンを参照してください。

于 2013-11-05T05:13:14.740 に答える