Cyb*_*kie 6 javascript google-maps google-maps-api-3
我在LatLngBounds数组中按关键字搜索地点.
var boundsarr = new Array();
boundsarr[0] = new google.maps.LatLngBounds(
new google.maps.LatLng(25.941886953491675, -80.17411103748543),
new google.maps.LatLng(25.947676224813897, -80.16767330177947)
);
boundsarr[1] = new google.maps.LatLngBounds(
new google.maps.LatLng(25.941886953491675, -80.16767330177947),
new google.maps.LatLng(25.94622890698334, -80.1644544339265)
);
boundsarr[2] = new google.maps.LatLngBounds(
new google.maps.LatLng(25.927413775186118, -80.1644544339265),
new google.maps.LatLng(25.94622890698334, -80.15962613214703)
);
boundsarr[3] = new google.maps.LatLngBounds(
new google.maps.LatLng(25.927413775186118, -80.15962613214703),
new google.maps.LatLng(25.931755728677782, -80.15801669822054)
);
boundsarr[4] = new google.maps.LatLngBounds(
new google.maps.LatLng(25.927413775186118, -80.15801669822054),
new google.maps.LatLng(25.933203046508336, -80.15318839644107)
);
boundsarr[5] = new google.maps.LatLngBounds(
new google.maps.LatLng(25.92886109301667, -80.15318839644107),
new google.maps.LatLng(25.933203046508336, -80.15157896251458)
);
Run Code Online (Sandbox Code Playgroud)
然后在地图,to和数组上添加标记,并使用markers数组创建返回的地点列表.重复的条目显示在列表中,我无法弄清楚为什么..
示例:http://jsfiddle.net/2KrmY/.如何防止重复显示?任何帮助是极大的赞赏!
作为临时解决方案,您是否可以每次在回调中构建一个找到的位置数组,然后在同一个循环中,查看该位置的计数是否 >1,如果是,则不调用 createMarker?
不确定是否完美,但见下文:
var foundPlaces = [];
var found;
function callback(results, status) {
if (status === google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
found = 0;
foundPlaces.push(results[i].id);
for (var j = 0; j < foundPlaces.length; j++) {
if (foundPlaces[j] === results[i].id) {
found++;
console.log(foundPlaces[j], results[i].id);
}
}
if (found < 2) {
createMarker(results[i]);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1226 次 |
| 最近记录: |