ボックス内のオブジェクトを検索するために使用するデモがあります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
ボックスの外側のスクリプト検索オブジェクトを使用する必要がありますか? どうすればこれを解決できますか?