0

当我右键单击 Google map 时,我想在我的鼠标在地图上的确切位置显示一个菜单框。我知道我可以使用 Google 地图活动,但我不知道该怎么做。我比 Javascript 更熟悉 jQuery。感谢你的帮助。

4

1 回答 1

1

rightclick此示例将帮助您并查看定义事件的代码末尾:

html:

<script src="http://code.jquery.com/jquery-1.7.2.min.js" type="text/javascript"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script src="https://dl.dropbox.com/u/15208254/stackoverflow/googlelocation/script.js" type="text/javascript"></script>
<div id="mapDiv" style="width:700px; height: 500px;"></div>

js:

$.geolocation.find(function(location) {
        var lat = location.latitude;
        var lng = location.longitude;

        var map = new google.maps.Map($('#mapDiv').get(0), {
            center: new google.maps.LatLng(lat, lng),
            zoom: 13,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        });

        var pinColor = "FE7569";
        var pinImage = new google.maps.MarkerImage("http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=%E2%80%A2|" + pinColor,
        new google.maps.Size(21, 34),
        new google.maps.Point(0,0),
        new google.maps.Point(10, 34));
        var pinShadow = new google.maps.MarkerImage("http://chart.apis.google.com/chart?chst=d_map_pin_shadow",
        new google.maps.Size(40, 37),
        new google.maps.Point(0, 0),
        new google.maps.Point(12, 35))

        var marker = new google.maps.Marker({
            position: new google.maps.LatLng(lat, lng),
            map: map,
            icon: pinImage,
            shadow: pinShadow 
        });

    /* click event for the map */
    google.maps.event.addListener(map, 'rightclick', function() {
        alert('right click detected!');
    });
});

现场演示:

http://jsfiddle.net/oscarj24/sPsxh/1/

于 2012-08-09T19:22:53.660 回答