2012-06-26 16 views
0

我試圖在Bing地圖的EntityLayer上顯示多個Pushpin對象。雖然Pushpins正在檢索數據,而EntityLayer正確存儲Pushpins,但MapView未顯示EntityLayerEntityLayer未鏈接到MapView

JSONObject json = retrieveJSON(); 
JSONArray array = json.getJSONArray("Sites"); 

Coordinate closestGauge; 

fooLayer = new EntityLayer("foos"); 


for(int i = 0; i < array.length(); i++) 
{ 
    JSONObject site = array.getJSONObject(i); 
    double lon = site.getDouble("Longitude"); 
    double lat = site.getDouble("Latitude"); 
    Pushpin foo = null; 
    fooCoordinate = new Coordinate(lat, lon); 
    PushpinOptions fooData = new PushpinOptions(); 
    fooData.Text = Double.toString(site.getDouble("Data")); 
    fooData.Icon = Constants.PushpinIcons.RedFlag; 
    foo = new Pushpin(fooCoordinate, fooData); 
    _FWSGPSLayer.add(foo); 
} 

fooMap.getLayerManager().addLayer(fooLayer); 
fooLayer.updateLayer(); 

通過Debug透視圖一起去,我注意到EntityLayer從來沒有鏈接到MapView_map參數/值始終設置爲null。我已經嘗試了各種顯示圖層的方法,例如從EntityLayer調用setBingMapsView方法,但目前爲止沒有任何工作。

有什麼我做錯了嗎?我試圖將示例與示例Bing地圖應用程序進行匹配,但它並沒有提供幫助。

編輯:我已經做了一些調試,這是我迄今發現的:當我註釋掉for循環,並簡單地添加一個圖釘,它的工作原理。這使我相信Bing地圖對可添加的圖釘數量有限制。但是,我的數組只包含〜200個數據點,而我被引導認爲上限是數千。

回答

0

好吧,傻我。通過我的JSONArray沖刷,我注意到,散佈在我的陣列中,幾個Doubles實際上返回null。當然,由於我正在使用幾乎不變的Location更新進行Android設備上的調試,所以我幾乎無法在LogCat中找到NullPointerException

經驗教訓,請始終檢查nulls