如何调整 Azure Maps 以获得正确的位置?

Posted

技术标签:

【中文标题】如何调整 Azure Maps 以获得正确的位置?【英文标题】:How to tune Azure Maps to get the corract location? 【发布时间】:2020-11-01 03:51:04 【问题描述】:

我对 Azure Maps 的动画库感兴趣。设置帐户并初始化地图后。我发现我作为参数输入的坐标不是它显示的坐标。 例如,我目前住在突尼斯。所以我将中心坐标设置为 (36.800697, 10.181198)。 但是,出于某种原因,地图以亚的斯亚贝巴为中心。我目前正在关注他们的代码示例“沿路径设置动画标记”。 [Github 链接][1] 如您所见,我设置了一堆模拟坐标。 PS:在以下示例中,我将屏蔽我的密钥。

 <!DOCTYPE html>
<html lang="en">
<head>
    <title>Animate marker along path - Azure Maps Web SDK Samples</title>

    <meta charset="utf-8" />
    <link rel="shortcut icon" href="/favicon.ico"/>
    <meta http-equiv="x-ua-compatible" content="IE=Edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
    <meta name="description" content="This sample shows how to easily animate a HTML marker along a path on the map." />
    <meta name="keywords" content="Microsoft maps, map, gis, API, SDK, animation, animate, animations, point, symbol, pushpin, marker, pin" />
    <meta name="author" content="Microsoft Azure Maps" />

    <!-- Add references to the Azure Maps Map control javascript and CSS files. -->
    <link rel="stylesheet" href="https://atlas.microsoft.com/sdk/javascript/mapcontrol/2.0/atlas.min.css">
    <script src="https://atlas.microsoft.com/sdk/javascript/mapcontrol/2/atlas.min.js"></script>

    <!-- Add reference to the animation module. -->
    <script src="../Common/scripts/azure-maps-animations.min.js"></script>

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

        //Create an array of points to define a path to animate along.
        var path = [
            [36.80067, 10.19111],
            [36.80081, 10.19077],
            [36.80148, 10.19548],
            [36.83469, 10.30360]
        ];

        function GetMap() 
            //Initialize a map instance.
            map = new atlas.Map('myMap', 
                center: [36.817421, 10.305192],
                zoom: 13,
                view: 'Auto',
                
        //Add your Azure Maps key to the map SDK. Get an Azure Maps key at https://azure.com/maps. NOTE: The primary key should be used as the key.
                authOptions: 
                    authType: 'subscriptionKey',
                    subscriptionKey: '<key>'
                
            );

            //Wait until the map resources are ready.
            map.events.add('ready', function () 
                //Create a data source and add it to the map.
                datasource = new atlas.source.DataSource();
                map.sources.add(datasource);

                //Add a line for the path as a visual reference.
                datasource.add(new atlas.data.LineString(path));
           
                //Add a layer for rendering line data. 
                map.layers.add(new atlas.layer.LineLayer(datasource));

                //Create a marker and add it to the map.
                marker = new atlas.HtmlMarker(
                    position: [-122.33825, 47.53945]
                );
                map.markers.add(marker);

                map.events.add('click', function () 
                    if (animation) 
                        //Restart the animation.
                        animation.reset();
                        animation.play();
                     else 
                        animation = atlas.animations.moveAlongPath(path, marker,  duration: 2000, captureMetadata: true, autoPlay: true );
                    
                );
            );
        
    </script>
</head>
<body onload="GetMap()">
    <div id="myMap" style="position:relative;width:100%;min-width:290px;height:600px;"></div>

    <div style="position:absolute;top:0px;left:calc(50% - 100px);background-color:white;padding:5px;">Click the map to animate marker.</div>

    <fieldset style="width:calc(100% - 30px);min-width:290px;margin-top:10px;">
        <legend><h1 style="font-size:16px">Animate marker along path</h1></legend>
        This sample shows how to easily animate a HTML marker along a path on the map.
        This sample uses the open source <a href="https://github.com/Azure-Samples/azure-maps-animations" target="_blank">Azure Maps Animation module</a>
    </fieldset>
</body>
</html>

【问题讨论】:

【参考方案1】:

你颠倒了经度和纬度。 azure-maps 库首先需要经度:

map = new atlas.Map('myMap', 
                center: [10.305192, 36.817421],
                zoom: 13,
                view: 'Auto',
                
        //Add your Azure Maps key to the map SDK. Get an Azure Maps key at https://azure.com/maps. NOTE: The primary key should be used as the key.
                authOptions: 
                    authType: 'subscriptionKey',
                    subscriptionKey: '<key>'
                
            );

【讨论】:

正确。 Azure Maps 与使用 [经度、纬度] 格式的地理空间系统保持一致。地理空间社区首选它的原因之一是它与 [x, y] 对齐

以上是关于如何调整 Azure Maps 以获得正确的位置?的主要内容,如果未能解决你的问题,请参考以下文章

如何获得当前位置?

正确的地址格式以从 google GeoCoding API 获得最准确的结果

Azure映射路由响应到Windows.Services.Maps.MapControl

使用 jquery 调整 Google Maps api v3 DIV 的大小 - 磁贴未正确刷新

如何在两个位置之间获得多条路线?

EPSG:3857 坐标系统与 Azure Maps 的兼容性