Google API:标记形成时的通知

时间:2012-10-24 08:08:17

标签: javascript google-maps geolocation google-maps-api-2

我正在使用谷歌地图API V2,我有像形状的geozones。现在想要在单位(简单标记)进入形状协调时获得警报。我怎么能这样做?

1 个答案:

答案 0 :(得分: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. 构造一个多边形并在地图中引入一些标记
  2. 当它在区域中找到标记时,您必须发出警报 所以对于1你可以参考上面的js作为2的样本你可以参考下面已经包含在这个论坛的讨论......
  3. 希望这会有所帮助:D

    google maps v3: check if point exists in polygon