我正在使用谷歌地图 API V2,我有像形状这样的地理区域。现在想要在单位(简单标记)将成为形状坐标时得到警报。我怎么能这样做?
问问题
991 次
1 回答
1
<script type ="text/javascript">
$(document).ready(function () {
function changeMarker(marker) {
marker.setIcon("images/bluemarker.png");
}
var map;
var infowindow;
var info1;
var triangleCoords = [];
function InitializeMap() {
var myOptions =
{
zoom: 5,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map"), myOptions);
triangleCoords = [
new google.maps.LatLng(20.874252, -80.190262),
new google.maps.LatLng(18.466465, -66.118292),
new google.maps.LatLng(32.321384, -64.75737),
new google.maps.LatLng(20.874252, -80.190262)
];
// Construct the polygon
// Note that we don't specify an array or arrays, but instead just
// a simple array of LatLngs in the paths property
Triangle = new google.maps.Polygon({
paths: triangleCoords,
strokeColor: "#FF0000",
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: "#FF0000",
fillOpacity: 0.35
});
Triangle.setMap(map);
}
function markicons() {
InitializeMap();
var ltlng = [];
var markers = [];
ltlng.push(new google.maps.LatLng(22.76, -79.28));
ltlng.push(new google.maps.LatLng(18.76, 83.30));
map.setCenter(triangleCoords[0]);
for (var i = 0; i < ltlng.length; i++) {
marker = new google.maps.Marker({
map: map,
position: ltlng[i],
draggable: true,
//icon: "images/greymarker.png",
animation: google.maps.Animation.DROP,
title: "this is " + i + "marker"
});
}
}
window.onload = markicons;
});
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server" >
<h2>Multiple Markers :</h2>
<div id="map-container"><div id="map"></div></div>
</asp:Content>
你的问题有两个部分
- 构建一个多边形并在地图中引入一些标记
- 当它在该区域找到一个标记时,您必须发出警报,因此对于 1,您可以参考上面的 js 作为 2 的示例,您可以参考下面已经包含在本论坛中的讨论......
希望这会有所帮助:D
于 2012-10-24T11:07:28.220 回答