Bing 地图包含位置功能

Joh*_*hes 0 bing-maps

我有一个同时使用 Bing 和 Google 地图的网站。每个功能都有 Bing 和 Google 版本。我在 Bing 地图中复制 google.maps.geometry.poly.containsLocation 函数时遇到问题。有这样的事情吗?

基本上,我构建了一个多边形,并希望确定图钉是否位于地图上的多边形内。

rbr*_*itt 5

Bing Maps V8 有一个空间数学模块,它可以使用 intersects 函数轻松地为您进行计算:

<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
    </head>
    <body>
        <div id='myMap' style='width: 100vw; height: 100vh;'></div>
        <script type='text/javascript'>
            function load() {
                var map = new Microsoft.Maps.Map(document.getElementById('myMap'), {
                    credentials: 'YOUR BING MAPS KEY'
                });

                //Create a polygon and location for testing.    
                var center = map.getCenter();
                var polygon = new Microsoft.Maps.Polygon([new Microsoft.Maps.Location(center.latitude - 0.05, center.longitude - 0.05),
                    new Microsoft.Maps.Location(center.latitude + 0.01, center.longitude - 0.05),
                    new Microsoft.Maps.Location(center.latitude + 0.01, center.longitude + 0.05)], { fillColor: 'yellow', strokeColor: 'orange',
                    strokeThickness: 5, strokeDashArray: [1, 2, 5, 10] });
                map.entities.push(polygon);

                var location = new Microsoft.Maps.Location(center.latitude, center.longitude);

                //Load the Spatial Math module
                Microsoft.Maps.loadModule('Microsoft.Maps.SpatialMath', function () {
                    //Check to see if the shapes intersect.
                    var intersects = Microsoft.Maps.SpatialMath.Geometry.intersects(location, polygon);

                    if(intersects){
                        alert("The location is inside in the polygon");        
                    } else {
                    alert("The location is NOT inside in the polygon");        
                                    }
                });     
            }
        </script>
        <script type='text/javascript' src='https://www.bing.com/api/maps/mapcontrol?callback=load' async defer></script>
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)