September 2, 2011

Google Maps - Converting coordinates

We found that when converting the coordinates from Java double to Java int the notation makes all the difference:

When we used 1000000 instead of 1E6 the coordinates were rounded off and therefore up to one degree (110 km) off from the true location.


int lon = (int) item.getStatus().getGeo().mLongitude * 1000000
// rounded off coordinate lat :42000000 lon :-87000000

int lat = (int) (item.getStatus().getGeo().mLatitude * 1E6); 
// correct lat :42239902 lon :-87971504


Log.e("Map", "lat :" + lat + " lon :" + lon);
mPoints.put(item.getProfileImageUrl(), new GeoPoint(lat, lon));



Uki's Google Java Technology blog