【问题标题】:How to get latitude and longitude of poiner located on Map?如何获得位于地图上的指针的纬度和经度?
【发布时间】:2012-04-06 09:56:05
【问题描述】:

我目前正在使用 Google API 在 Google 地图上指出位置。

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

请帮忙, 谢谢

【问题讨论】:

    标签: javascript google-maps google-maps-api-3


    【解决方案1】:

    试试这个代码:

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

    希望对你有所帮助。

    【讨论】:

    猜你喜欢
    • 2023-03-22
    • 2011-08-18
    • 2015-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-13
    • 2020-08-09
    • 2011-07-06
    相关资源
    最近更新 更多