我正在使用Bing Maps Android SDK,我正在寻找一种方法来点击我创建的多边形并显示一个信息框.我已经能够为图钉完成此操作,但不能用于多边形.我已经看到了这个答案,但我的应用程序需要会生成数百个这样的多边形,而我正在寻找一个更快的解决方案,使用多边形上的addHandler方法.我知道这可能是SDK的AJAX v7风格,它是Android SDK的底层基础.
我为AJAX版本尝试的代码(使用此模拟器进行测试.)
map.entities.clear();
latlon = map.getCenter();
var polygon = new Microsoft.Maps.Polygon([new Microsoft.Maps.Location(latlon.latitude, latlon.longitude-0.15), new Microsoft.Maps.Location(latlon.latitude+0.1, latlon.longitude-0.05), new Microsoft.Maps.Location(latlon.latitude+0.1, latlon.longitude+0.05), new Microsoft.Maps.Location(latlon.latitude, latlon.longitude+0.15), new Microsoft.Maps.Location(latlon.latitude-0.1, latlon.longitude+0.05), new Microsoft.Maps.Location(latlon.latitude-0.1, latlon.longitude-0.05), new Microsoft.Maps.Location(latlon.latitude, latlon.longitude-0.15)], null);
Microsoft.Maps.Events.addHandler(polygon, 'click', DisplayInfo);
map.setView( {zoom:10});
map.entities.push(polygon);
function DisplayInfo (e) {
var vertices = e.target.getLocations();
var verticeCenter = new Microsoft.Maps.Location(0,0);
//Calculating location of center
for (i=0; i<vertices.length-1; i++) {
verticeCenter.latitude = verticeCenter.latitude + vertices[i].latitude;
verticeCenter.longitude = verticeCenter.longitude + …Run Code Online (Sandbox Code Playgroud)