如何添加一个半径的圆Bing地图?

问题描述:

我已经看到了在这里做的: http://www.somebody4u.com/Profile/Live

I've seen it done here: http://www.somebody4u.com/Profile/Live

但我不能找到一个方法来与API(AJAX)做到这一点。

but I can't find a way to do it with the api (ajax).

Bing地图V7不包括平局圆法。

Bing Maps V7 does not include a draw circle method.

圆已被aproximated通过绘制几个小部分。

The circle has to be "aproximated" by drawing several small segments.

var key = .....; // API access key

var MM = Microsoft.Maps;
var R = 6371; // earth's mean radius in km

var map = new Microsoft.Maps.Map(this.element[0], {credentials: key, disableKeyboardInput: true});

var radius = ...;      //radius of the circle
var latitude = ...;    //latitude of the circle center
var longitude = ...;   //longitude of the circle center

var backgroundColor = new Microsoft.Maps.Color(10, 100, 0, 0);
var borderColor = new Microsoft.Maps.Color(150, 200, 0, 0);

var lat = (latitude * Math.PI) / 180;     
var lon = (longitude * Math.PI) / 180;
var d = parseFloat(radius) / R;
var circlePoints = new Array();

for (x = 0; x <= 360; x += 5) {
    var p2 = new MM.Location(0, 0);
    brng = x * Math.PI / 180;
    p2.latitude = Math.asin(Math.sin(lat) * Math.cos(d) + Math.cos(lat) * Math.sin(d) * Math.cos(brng));

    p2.longitude = ((lon + Math.atan2(Math.sin(brng) * Math.sin(d) * Math.cos(lat), 
                     Math.cos(d) - Math.sin(lat) * Math.sin(p2.latitude))) * 180) / Math.PI;
            p2.latitude = (p2.latitude * 180) / Math.PI;
            circlePoints.push(p2);
}

var polygon = new MM.Polygon(circlePoints, { fillColor: backgroundColor, strokeColor: borderColor, strokeThickness: 1 });

map.entities.push(polygon);