I have an offline-map App which uses GPS-Tracker. My primary goal is to sense changes in latitude and longitude and update a TextView
.
My GPS-Tracker
class is implemented as follows:
public class GPSTracker extends Service implements LocationListener {
...
public GPSTracker(Context context) {
...
getLocation();
}
public Location getLocation() {
// returns Location
}
@Override
public void onLocationChanged(Location location) {
// Method 1: update UI elements (textview) directly
MainActivity.tvGPS.setText("lat: " + Double.toString(location.getLatitude()) + "lon: " + Double.toString(location.getLongitude());
// Method 2: call a method from MainActivity which updates UI
MainActivity.setNewPosition(location.getLatitude() , location.getLatitude());
// Method 3: sense changes in Latitude and Longitude directly in MainActivity and update UI
}
}
Question:
How can I directly sense changes of Latitude and Longitude (in MainActivity
) and modify UI.
what I so far tested:
LocalBroacastManager
as mentioned here but it demands constantly checking of location to detect changes
Observer Pattern
as mentioned here: changes are sensible only in Observer
Class not in MainActivity