繁体   English   中英

如何获取位于Map的指针的经纬度?

[英]How to get latitude and longitude of poiner located on Map?

我目前正在使用谷歌 API 指向谷歌 map 上的 position。

这是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() function 时,我必须获得当前定位的标记纬度经度。

请帮助,谢谢

试试这个代码:

<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>

我希望这对你有帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM