使用本地GeoJSON对象的Bing地图上的多边形导致错误的位置

时间:2018-12-10 18:56:20

标签: bing-maps

我使用Bing Map v8在地图上绘制多边形。 由于某种原因,即使我使用相同的坐标,两种不同的方法也会导致不同的结果。

此方法 如here所示 效果很好:

        map = new Microsoft.Maps.Map(document.getElementById("map"), {
            credentials: '',
            mapTypeId: Microsoft.Maps.MapTypeId.aerial,

        });

        var polygon = new Microsoft.Maps.Polygon([
            new Microsoft.Maps.Location(32.57922,34.91395),
            new Microsoft.Maps.Location(32.53799,34.9021),
            new Microsoft.Maps.Location(32.53264,34.91292),
            new Microsoft.Maps.Location(32.55398,34.92339),
            new Microsoft.Maps.Location(32.57156,34.93489),
            new Microsoft.Maps.Location(32.57503,34.92614)],
            { fillColor: 'rgba(241, 227, 100, 0.3)', strokeColor: 'rgba(241, 227, 100, 0.8)', strokeThickness: 1 });


        map.entities.push(polygon);

使用here所示的Microsoft.Maps.GeoJson.read方法读取具有相同多边形坐标的GeoJson对象时,将在距原始位置西北数百英里的区域绘制多边形。为什么呢?

map = new Microsoft.Maps.Map(document.getElementById("map"), {
                credentials: '',
                mapTypeId: Microsoft.Maps.MapTypeId.aerial,

            });

            //define polygon using GeoJson Object
            var GeoJson = {
            "type": "Polygon",
            "coordinates": [[
                    [32.57922,34.91395],
                    [32.53799,34.9021],
                    [32.53264,34.91292],
                    [32.55398,34.92339],
                    [32.57156,34.93489],
                    [32.57503,34.92614]
                ]]
            };

            //Load the GeoJson Module.
            Microsoft.Maps.loadModule('Microsoft.Maps.GeoJson', function () {

                //Parse the GeoJson object into a Bing Maps shape.
                var shape = Microsoft.Maps.GeoJson.read(GeoJson, {
                    polygonOptions: {
                        fillColor: 'rgba(255,0,0,0.5)',
                        strokeColor: 'rgba(241, 227, 100, 0.8)',
                        strokeThickness: 1
                    }
                });
                //Add the shape to the map.
               //results in wrong location !
                map.entities.push(shapeA);
            });         

1 个答案:

答案 0 :(得分:2)

Bing地图的位置采用纬度,经度,而GeoJSON位置/坐标为经度/纬度。反转GeoJSON坐标中的数字。