Hi guys, I'm having little trouble with getting current location point.
Portion of my code:
locationDisplay.setAutoPanMode(LocationDisplay.AutoPanMode.RECENTER);
locationDisplay.addLocationChangedListener(new LocationDisplay.LocationChangedListener() {
@Override
public void onLocationChanged(LocationDisplay.LocationChangedEvent locationChangedEvent) {
// Log.i(TAG, "HERE is the Location " + Double.toString(locationChangedEvent.getLocation().getPosition().getY()) + " "
// + Double.toString(locationChangedEvent.getLocation().getPosition().getX())
// );
Latitude = Double.toString(locationChangedEvent.getLocation().getPosition().getY());
Longitude = Double.toString(locationChangedEvent.getLocation().getPosition().getX());
Log.i(TAG, Latitude + " *** " + Longitude);
}
});
if(!locationDisplay.isStarted())
locationDisplay.startAsync();
//this line prints null
Log.i(TAG,"LOCATION IS STARTED!" + Latitude + " " + Longitude);
The problem I having is that, I'm trying get the current location points. When I run the app, only this statement prints the data
Log.i(TAG, "HERE is the Location " + Double.toString(locationChangedEvent.getLocation().getPosition().getY()) + " "
+ Double.toString(locationChangedEvent.getLocation().getPosition().getX())
);
but,
Log.i(TAG,"LOCATION IS STARTED!" + Latitude + " " + Longitude);
this prints null on both variable. Since I have assigned the Longitude and Latitude variable on the OnLocationChanged method, why does this prints null. Is there any way I can fix this problem.
Output:
02-15 23:35:10.357 23095-23095/com.example.moham.esrimap I/progress: LOCATION IS STARTED!null null
02-15 23:35:12.314 23095-23095/? I/progress: 38.9808961 *** -125.3387306
02-15 23:35:12.315 23095-23095/? I/progress: 38.9808961 *** -125.3387306
Thanks!