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

标签 javascript azure geolocation maps azure-maps

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

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

最佳答案

您颠倒了经度和纬度。 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>'
                }
            });

关于javascript - 如何调整 Azure Maps 以获得正确的位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64628510/

相关文章:

javascript - jQuery 进度条仅在第一个加载

javascript - 如何更改存储在数组中的变量的类名?

python - Azure AD : Change user password from Custom App

azure - Azure WebJob 上的 HTTP 请求/响应

android - 在 Android 中步行/驾驶时更新位置标记并在 Google map 上绘制路径

javascript 代码在插入 html 地理定位 map 时不起作用

javascript - 选择下拉列表不绑定(bind)值

javascript - 是否可以确定 HTML5 div 标签的最小宽度?

Azure 服务总线发送吞吐量 .Net SDK

windows-phone-8 - 如何将经纬度值转换为Windows Phone中的地址?