0

我目前正在使用谷歌 API 来指向谷歌地图上的位置。

这是google-maps-utility-library-v3

与链接

http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/docs/reference.html

我写了这段代码

<script type="text/javascript">

        function initialize() {
        var secheltLoc = new google.maps.LatLng(49.47216, -123.76307);
        var myMapOptions = {
             zoom: 15
            ,center: secheltLoc
            ,mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var theMap = new google.maps.Map(document.getElementById("map_canvas"), myMapOptions);
        var marker = new google.maps.Marker({
            map: theMap,
            draggable: true,
            position: new google.maps.LatLng(49.47216, -123.76307),
            visible: true
        });
    }
    function getLatLong(){
    var secheltLoc = new google.maps.LatLng(49.47216, -123.76307);
        var myMapOptions = {
             zoom: 15
            ,center: secheltLoc
            ,mapTypeId: google.maps.MapTypeId.ROADMAP
        };
    var theMap = new google.maps.Map(document.getElementById("map_canvas"), myMapOptions);
    var marker = new google.maps.Marker({
            map: theMap,
            draggable: true,
            position: new google.maps.LatLng(49.47216, -123.76307),
            visible: true
        });
    infoBox = new InfoBox({latlng: marker.getPosition()});
    <!--  var getLat = new InfoBox(); -->
     alert(InfoBox.prototype.getPosition);
    }
</script>

<body onload="initialize()">
   <div id="map_canvas" style="width:100%; height:50%"></div>
   <input type="button" onclick="getLatLong();" />
   <div id="letLong"></div>

我想要的是当我单击此getLatLong()功能时,我必须获取当前定位的标记纬度经度。

请帮忙,谢谢

4

1 回答 1

0

试试这个代码:

<script type="text/javascript">
    var marker=null;

    function initialize()
    {
        var secheltLoc = new google.maps.LatLng(49.47216, -123.76307);
        var myMapOptions = {
            zoom:15, center:secheltLoc, mapTypeId:google.maps.MapTypeId.ROADMAP
        };
        var theMap = new google.maps.Map(document.getElementById("map_canvas"), myMapOptions);
        marker = new google.maps.Marker({
            map:theMap,
            draggable:true,
            position:new google.maps.LatLng(49.47216, -123.76307),
            visible:true
        });
    }
    function getLatLong()
    {
        alert(marker.position);
    }
</script>

我希望这对你有帮助。

于 2012-04-06T10:03:53.570 回答