簡體   English   中英

獲取事件點擊的緯度和經度 - Bing Maps 和 webv8

[英]Get latitude and longitude on event click - Bing Maps and webv8

我正在使用 Bing 地圖 API...

我想獲得點擊功能的緯度和經度。 這是我的 HTML 代碼:

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="utf-8" />
    <script type='text/javascript' src='http://www.bing.com/api/maps/mapcontrol?callback=GetMap&key=[YOUR_BING_MAPS_KEY]' async defer></script>
</head>
<body>
    <div id="myMap" style="position:relative;width:600px;height:400px;"></div>
    <script type='text/javascript'>
        var map;

        function GetMap() {
            map = new Microsoft.Maps.Map('#myMap', {});
            Microsoft.Maps.Events.addHandler(map, 'click', function () { set_latitudes_and_longitude(map); });
        }

        function set_latitudes_and_longitude(map)
        {
            console.log(map);
            // How can I wright something like
            // map.getLat or map.getLong?

        }
    </script>
</body>
</html>

console.log(map); 我沒有找到任何有關緯度和經度的信息...

我這樣做了,它奏效了:

<script type='text/javascript'>
    var map;

    function GetMap() {
        map = new Microsoft.Maps.Map('#myMap', {});
        Microsoft.Maps.Events.addHandler(map, 'click', function (e) { set_latitudes_and_longitude(e); });
    }

    function set_latitudes_and_longitude(map)
    {
        console.log(map.location.latitude);
        console.log(map.location.longitude);
        // How can I write something like 
        // map.getLat or map.getLong?
        
    }
</script>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM