I am trying to display multiple Pushpin objects on an EntityLayer for Bing Maps. While the Pushpins are retrieving data correctly and the EntityLayer is storing the Pushpins properly, the MapView is not displaying the EntityLayer.
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();
Going by the Debug perspective, I noted that the EntityLayer never links to the MapView as its _map parameter/value is always set to null. I’ve tried various ways of displaying the layer, such as calling the setBingMapsView method from EntityLayer but nothing has worked so far.
Is there something I’m doing wrong? I tried to match things up with the sample Bing Maps application, it hasn’t been helping.
EDIT: I’ve done some debugging and this is what I’ve found out so far: When I comment out the for loop and simply add a single Pushpin, it works. This leads me to believe that Bing Maps has a limit for the number of Pushpins that can be added. However, my array only contains ~200 data points whereas I have been led to believe that the upper limit is in the thousands.
Well, silly me. Scouring through my
JSONArray, I noticed that, interspersed throughout my array, a couple ofDoubleswere actually returningnull. Of course, since I was debugging on an Android device with a near-constant stream ofLocationupdates, I could hardly spot theNullPointerExceptionin my LogCat.Lesson learned, always check for
nulls.