Android / Java

Do you SEE this?! (Android Java – MapView Idiocracy)

Witness this please:

                Log.d("MAPVIEW", "1:"+(maxLat + minLat)/2+", 2:"+(maxLon + minLon)/2);
		//mapController.zoomToSpan((int)Math.abs(maxLat - minLat), (int)Math.abs(maxLon - minLon));
		mapController.zoomToSpan((int)((maxLat - minLat) * 1E6), (int)((maxLon - minLon)*1E6));
		//mapController.animateTo(new GeoPoint( (maxLat + minLat)/2, (maxLon + minLon)/2 )); 
 
		//mapController.zoomToSpan((int)Math.abs(0.5 * 1E6), (int)Math.abs(4 * 1E6));
		//mapController.animateTo(new GeoPoint(-49, -115));
		//mapController.animateTo(new GeoPoint( (maxLat + minLat)/2, (maxLon + minLon)/2 )); 
		//Log.d("MAPVIWE", "animating to: " + (int)Math.abs(49 * 1E6) + " / " + (int)Math.abs(-116 * 1E6));
		//mapController.animateTo(new GeoPoint((int)Math.abs(49 * 1E6), (int)Math.abs(-116 * 1E6)));
		//Log.d("MAPVIWE", "animating to: " + (int)(((maxLat + minLat)/2)*1E6) + " / " + (int)(((maxLon + minLon)/2)*1E6));
		mapController.animateTo(new GeoPoint((int)(((maxLat + minLat)/2)*1E6), (int)(((maxLon + minLon)/2)*1E6)));

this is the amalgamation of 3 days of tinkering with zoomToSpan and animateTo methods for the MapView.

What you can see here is a mess working with these methods. Were looking at trials and errors of figuring out these fussy functions in exactly what kind of data they are looking for. And of course were talking Lats and Longs here, this isn’t exactly “tolerant” data, this is micro precision numbers.

Ultimately heres the formula to work with these things, despite the documentation at google and the examples found at stackoverflow:

For zoomToSpan:
This method only takes two ints that have been converted to 1E6 microdegrees. Thats pretty much the only rule, but you will never know that looking at the documentation.

mapController.zoomToSpan((int)((maxLat - minLat) * 1E6), (int)((maxLon - minLon)*1E6));

for animateTo
This method takes a single GeoPoint that follows the exact same rules as zoomToSpan. Except instead of just throwing in a + or – operator between the two pieces of data, we need to also divide by 2 to grab the center most point.

mapController.animateTo(new GeoPoint((int)(((maxLat + minLat)/2)*1E6), (int)(((maxLon + minLon)/2)*1E6)));

Just LOOK at all of those brackets. Disgusting. I’m sure i could remove one or two tops, but as far as im concerned, this works, and im now leaving it alone :\

Tags: , , , , , ,

Wednesday, January 4th, 2012 Android / Java, Programming No Comments