Microsoft Bing地图图钉(Web javascript)

时间:2018-09-25 10:30:44

标签: bing-maps

是否可以从地址而不是经/长数据创建图钉?

我想图钉构造器只接受位置的经纬度表示。

新的Microsoft.Maps.Pushpin(值)

是否有用于从地址创建图钉的解决方案。

1 个答案:

答案 0 :(得分:1)

以下是示例代码,向您显示如何通过地址查找位置:

<!DOCTYPE html>
<html>
    <head>
        <title>searchbyaddressHTML</title>
        <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
        <style type='text/css'>body{margin:0;padding:0;overflow:hidden;font-family:'Segoe UI',Helvetica,Arial,Sans-Serif}</style>
    </head>
    <body>
        <div id='printoutPanel'></div>

        <div id='myMap' style='width: 100vw; height: 100vh;'></div>
        <script type='text/javascript'>
            function loadMapScenario() {
                var map = new Microsoft.Maps.Map(document.getElementById('myMap'), {
                    /* No need to set credentials if already passed in URL */
                    center: new Microsoft.Maps.Location(47.624527, -122.355255),
                    zoom: 8 });
                Microsoft.Maps.loadModule('Microsoft.Maps.Search', function () {
                    var searchManager = new Microsoft.Maps.Search.SearchManager(map);
                    var requestOptions = {
                        bounds: map.getBounds(),
                        where: 'Washington, DC',
                        callback: function (answer, userData) {
                            map.setView({ bounds: answer.results[0].bestView });
                            map.entities.push(new Microsoft.Maps.Pushpin(answer.results[0].location));
                        }
                    };
                    searchManager.geocode(requestOptions);
                });

            }
        </script>
        <script type='text/javascript' src='https://www.bing.com/api/maps/mapcontrol?key=YourBingMapsKey&callback=loadMapScenario' async defer></script>
    </body>
</html>
相关问题