如何添加一个半径的圆Bing地图? [英] How do I add a radius circle to Bing Maps?

查看:83
本文介绍了如何添加一个半径的圆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);

这篇关于如何添加一个半径的圆Bing地图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆