I’m trying to put some geolocation data from Google Maps into a database. But passing around a GeoPoint object, I seem to be loosing a ton of precision.
I get an Intent as a result of an onActivityResult response, in the Intent is extra data for a geopoint:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d(TAG,String.format("doMark returns with %d", resultCode));
int lat = data.getIntExtra("MARK_LAT", 0);
int lng = data.getIntExtra("MARK_LNG", 0);
Log.d(TAG, String.format("Orig lat/lng %d:%d", lat, lng));
OverlayItem oi = new OverlayItem(new GeoPoint(lat,lng), "ID", "");
Log.d(TAG, String.format("GeoPoint lat/lng %d:%d",
oi.getPoint().getLatitudeE6(),
oi.getPoint().getLongitudeE6()));
m_data.addMarker(m_gp, data.getIntExtra("MARK_ID", R.drawable.tile5));
super.onActivityResult(requestCode, resultCode, data);
}
In the logcat I get:
03-08 10:28:16.164: D/TREASUREACTIVITY(1653): Orig lat/lng 42234412:-70999749
03-08 10:28:16.164: D/TREASUREACTIVITY(1653): GeoPoint lat/lng 42234412:-70999749
That looks good! The GeoPoint lat/lng are the same as the input values.
The m_data.addMarker() function is thus:
public void addMarker(GeoPoint p, int id) {
SQLiteDatabase db = getWritableDatabase();
ContentValues values = new ContentValues();
values.put("TIME", System.currentTimeMillis());
values.put("LAT", p.getLatitudeE6());
values.put("LNG", p.getLongitudeE6());
values.put("MARK_ID", id);
db.insert("MARKER", null, values);
Log.d(TAG,String.format("INSERT MARKER %d %d",p.getLatitudeE6(),
p.getLongitudeE6()));
db.close();
}
The logcat from addMarker() is:
03-08 10:28:16.194: D/DDATA(1653): INSERT MARKER 42234000 -71000000
I’m presuming there’s some kind of conversion/promotion going on behind the scenes… but the code is pretty straight forward.
Any guess as to where the precision went?
Your
addMarkercall is usingm_gp, notoi.getPoint()– so it’s not using the same value at all.Maybe that’s not the real problem, but you may just need: