【问题标题】:Displaying markers within a Bing maps Polygon在 Bing 地图多边形中显示标记
【发布时间】:2013-03-12 11:19:45
【问题描述】:

我正在使用 Bing 地图在地图上显示标记。

现在我添加了一个功能,允许用户围绕他选择的任何标记画一个圆圈,并让他以公里为单位指定圆圈的半径。

我希望圆圈(多边形)包含该圆圈的纬度/经度范围内的标记,并且圆圈外的标记消失。

我如何做到这一点?

【问题讨论】:

    标签: html bing markers polygons


    【解决方案1】:

    您没有提供任何代码。

    但是,我参与了一个类似的项目,所以我知道你在说什么。 既然您正在寻找自定义多边形,您可以看看这个link

    另一种方法是使用标记的 x,y 坐标并使用 Javascript 在地图周围画一个圆圈。

    这个 JAVASCRIPT 应该有帮助

    function drawCircle(radius, origin) {
        var RadPerDeg = Math.PI / 180;
        var earthRadius = 3959;  
        var lat = origin.latitude * RadPerDeg;
        var lon = origin.longitude * RadPerDeg;
        var locs = new Array();
        var AngDist = parseFloat(radius) / earthRadius;
        for (x = 0; x <= 360; x++) { //making a 360-sided polygon
            var pLatitude, pLongitude;
            // With a nice, flat earth we could just say p2.Longitude = lon * sin(brng) and p2.Latitude = lat * cos(brng)
            // But it ain't, so we can't.  See http://www.movable-type.co.uk/scripts/latlong.html
            brng = x * RadPerDeg;
            pLatitude = Math.asin(Math.sin(lat) * Math.cos(AngDist) + Math.cos(lat) * Math.sin(AngDist) * Math.cos(brng)); //still in radians
            pLongitude = lon + Math.atan2(Math.sin(brng) * Math.sin(AngDist) * Math.cos(lat), Math.cos(AngDist) - Math.sin(lat) * Math.sin(pLatitude));
            pLatitude = pLatitude / RadPerDeg;
            pLongitude = pLongitude / RadPerDeg;
            locs.push(new MM.Location(pLatitude, pLongitude));
        };
        circle = new MM.Polyline(locs, { visible: true, strokeThickness: 2, strokeDashArray: "1", strokeColor: new MM.Color(200, 0, 0, 200, 0) });
        map.entities.push(circle);
    };
    

    【讨论】:

    • 很长一段时间后我又回来了。我解决了我的问题。解决方案与您提供的类似。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多