下面是我的代碼,其中包含表示邊界項的地圖上的邊界和矩形圖的數組。谷歌地圖將矩形合併爲一個多邊形並搜索它
是否有可能將多個矩形/邊界合併爲一個多邊形?目標是在通過合併矩形創建的多邊形內進行搜索。
例如在合併界限內搜索位置而不是單獨界定每個界限。
function createBounds() {
var bounds = new Array();
bounds[0] = new google.maps.LatLngBounds(
new google.maps.LatLng(25.941886953491675, -80.17411103748543),
new google.maps.LatLng(25.947676224813897, -80.16767330177947)
);
bounds[1] = new google.maps.LatLngBounds(
new google.maps.LatLng(25.941886953491675, -80.16767330177947),
new google.maps.LatLng(25.94622890698334, -80.1644544339265)
);
bounds[2] = new google.maps.LatLngBounds(
new google.maps.LatLng(25.927413775186118, -80.1644544339265),
new google.maps.LatLng(25.94622890698334, -80.15962613214703)
);
bounds[3] = new google.maps.LatLngBounds(
new google.maps.LatLng(25.927413775186118, -80.15962613214703),
new google.maps.LatLng(25.931755728677782, -80.15801669822054)
);
bounds[4] = new google.maps.LatLngBounds(
new google.maps.LatLng(25.927413775186118, -80.15801669822054),
new google.maps.LatLng(25.933203046508336, -80.15318839644107)
);
bounds[5] = new google.maps.LatLngBounds(
new google.maps.LatLng(25.92886109301667, -80.15318839644107),
new google.maps.LatLng(25.933203046508336, -80.15157896251458)
);
drawRectangles(bounds);
}
// Draw the array of bounds as rectangles on the map
function drawRectangles(bounds) {
boundsRectangles = new Array(bounds.length);
for (var i = 0; i < bounds.length; i++) {
boundsRectangles[i] = new google.maps.Rectangle({
bounds: bounds[i],
fillOpacity: 0,
strokeOpacity: 1.0,
strokeColor: '#000000',
strokeWeight: 1,
map: map
});
}
}
[Google Maps API檢查標記是否存在於多個邊界中]的可能重複(http://stackoverflow.com/questions/17253929/google-maps-api-check-if-marker-exists-in-multiple-bounds ) –
@ Dr.Molle對於公衆來說,它並不是真的重複,因爲問題是不同的。是的,前一個問題的答案與這個問題有關,但主題涉及標記。這裏我試圖合併邊界而不檢查標記是否存在。 – CyberJunkie
這裏你的問題是如何將多個邊界合併爲1個多邊形,而這正是你在副本中詢問的內容以及已經在那裏回答的問題 –