2012-06-21 19 views
5

Bing Maps Android SDK kullanıyorum ve oluşturduğum ve bir bilgi kutusu gösterdiğim çokgenlere tıklamanın bir yolunu arıyorum. Bunu bir raptiye için başardım, ama çokgen için değil. this answer'u gördüm, ancak uygulama gereksinimim yüzlerce çokgen oluşturacak ve çokgenler üzerinde addHandler yöntemini kullanarak daha hızlı bir çözüm arayacağım. Bunun, Android SDK'nın temelini oluşturan SDK'nın AJAX v7 aroması için mümkün olduğunu biliyorum.Bing Haritalar'da çokgenler üzerinde bilgi kutusu Android SDK

AJAX versiyonu için çalıştı kodu (this emülatörü kullanarak test etti.)

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 + vertices[i].longitude; 
    } 
    verticeCenter.latitude = verticeCenter.latitude/(vertices.length - 1); 
    verticeCenter.longitude = verticeCenter.longitude/(vertices.length - 1); 
    defaultInfobox = new Microsoft.Maps.Infobox(verticeCenter, {width: 200, height: 50});  
    map.entities.push(defaultInfobox); 
} 

Ancak, SDK'nın varlıkları klasöründen BingMapsAndroid.js benzer bir kod itti, ama bu kötü kokan Çalış. İşleyici, hasHandler yöntemini kullanarak kontrol ettiğim gibi eklenmiştir. Dokunmalar kaydedilir ve bunların lat ve uzun değerleri günlüğe gönderilir, ancak dokunma çokgenin içinde yer alsa bile poligon olayı çağrılmaz. BingMapsAndroid.js içinde

Poligon testi işlevi:

this.PolygonTest = function() { 
    _map.entities.clear(); 
    latlon = new Microsoft.Maps.Location(1,1); 
    console.log("Polygon test function"); 
    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); 

    try { 
    Microsoft.Maps.Events.addHandler(polygon, 'click', function(e) { console.log("Polygon click!"); }); //This is never evoked 
    Microsoft.Maps.Events.addHandler(_map, 'click', function(e) { var point = new MM.Point(e.getX(), e.getY()); var loc = e.target.tryPixelToLocation(point); console.log("lat: " + loc.latitude + ", lon: " + loc.longitude); }); 

    } catch(e) { 
     alert("Error"); 
    } 

    _map.setView({zoom:10}); 
    _map.entities.push(polygon); 

    if (Microsoft.Maps.Events.hasHandler(polygon,'click')) { 
     console.log("Polygon has click handler."); //This works 
    } 

    //This function should be added to the click handler for polygon. I'll add it when I know the handler works. 
    function DisplayInfo (e) { 
     console.log("Polygon has been clicked."); 
     var vertices = e.target.getLocations(); 
     var verticeCenter = new Microsoft.Maps.Location(0,0); 
     for (i=0; i<vertices.length-1; i++) { 
      verticeCenter.latitude = verticeCenter.latitude + vertices[i].latitude; 
      verticeCenter.longitude = verticeCenter.longitude + vertices[i].longitude; 
     } 
     verticeCenter.latitude = verticeCenter.latitude/(vertices.length - 1); 
     verticeCenter.longitude = verticeCenter.longitude/(vertices.length - 1); 
     defaultInfobox = new Microsoft.Maps.Infobox(verticeCenter, { width: 200, height: 50 }); 
     _map.entities.push(defaultInfobox); 
    } 
} 

cevap

3

çok testten sonra, ben sorunu Android yatıyor buldum. Ben AjaxV7 için Bing Maps İnteraktif SDK kod çalıştı ve bu benim sonuçlar şunlardır:

  • Masaüstü tarayıcılar: işleri (söz konusu yazıldığı gibi)
  • iPhone 4S: varsayılan
  • Android 2.3.4 çalışır tarayıcı: Opera ile
  • Android ICS çalışır: Opera ile
  • Android 2.3.4 çalışmıyor varsayılan tarayıcı ile
  • Android ICS çalışır: çalışmıyor