I have a GPSTracker
class which extends Service implements LocationListener
.
And GPSTracker
also override onLocationChanged
method.
In my MainActivity
, I created an instance of GPSTracker
and use custom methods I declared in GPSTracker
class to get lat/lon.
How can I make my MainActivity
to be notified when GPSTracker
's onLocationChanged
is triggered?
GPSTracker
Class
public class GPSTracker extends Service implements LocationListener {
...
Location location; // location
double latitude; // latitude
double longitude; // longitude
...
public GPSTracker(Context context) {
this.mContext = context;
getLocation();
}
public Location getLocation() {
...
return location;
}
public void stopUsingGPS(){
...
}
public double getLatitude(){
if(location != null){
latitude = location.getLatitude();
}
return latitude;
}
public double getLongitude(){
if(location != null){
longitude = location.getLongitude();
}
return longitude;
}
public boolean canGetLocation() {
return this.canGetLocation;
}
public void showSettingsAlert(){
...
// Showing Alert Message
alertDialog.show();
}
@Override
public void onLocationChanged(Location location) {
// do some stuff
}
@Override
public void onProviderDisabled(String provider) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public IBinder onBind(Intent arg0) {
return null;
}
}