0
I’m trying to use in Google Maps, the data that is in a database sqlite
, But I’m having trouble accessing the shuttle’s return.
I used the same logic to call using the database number and it worked, but for the map, it only returns 0.0 coordinate.
Follow the code, if anyone can help me where I’m going wrong, because I’ve been stuck at that point for a week.
public class MapsDetailActivity extends FragmentActivity implements OnMapReadyCallback, LoaderManager.LoaderCallbacks<Cursor>{
private static final int EXISTING_DATA_LOADER = 0;
private Uri mCurrentUri;
double placeLat, placeLong;
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps_detail);
Intent intent = getIntent();
mCurrentUri = intent.getData();
getLoaderManager().initLoader(EXISTING_DATA_LOADER, null, this);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
LatLng place = new LatLng(placeLat, placeLong);
mMap.addMarker(new MarkerOptions().position(place));
mMap.moveCamera(CameraUpdateFactory.newLatLng(place));
}
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
String[] projection = {GuideContract.GuideEntry._ID,
GuideContract.GuideEntry.COLUMN_PLACE_LATITUDE,
GuideContract.GuideEntry.COLUMN_PLACE_LONGITUDE};
return new CursorLoader(this,mCurrentUri, projection, null,null,null);
}
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
if (cursor.moveToFirst()){
int latColumnIndex = cursor.getColumnIndex(GuideContract.GuideEntry.COLUMN_PLACE_LATITUDE);
int lonColumnIndex = cursor.getColumnIndex(GuideContract.GuideEntry.COLUMN_PLACE_LONGITUDE);
int latitude = cursor.getInt(latColumnIndex);
int longitude = cursor.getInt(lonColumnIndex);
placeLat = latitude;
placeLong = longitude;
}
}
@Override
public void onLoaderReset(Loader<Cursor> loader) {
}
}
Solved, thank you very much!!!
– Erico Koerich