Skip to content Skip to sidebar Skip to footer

Android Gps Not Working For Me

My app has two activities that need GPS, so I tried to offload it to a separate class that either activity could use. I found an answer here that looked easy enough Android - Best

Solution 1:

GPS class constructor contains this row:

public GPS(IGPSActivity main) {
    this.main = main;

    // GPS Position
    mlocManager = (LocationManager) ((Activity) this.main).getSystemService(Context.LOCATION_SERVICE);
...
}

And your interface looks like this:

publicinterfaceIGPSActivity {
    publicvoidlocationChanged(double longitude, double latitude);

}

So, the GPS class get an interface, and you want to cast it into an Activity to get a system service from it. That is not going to work.

Change your GPS class a little bit. For example:

publicGPS(IGPSActivity main, Activity activity){
    mlocManager = (LocationManager) activity.getSystemService(Context.LOCATION_SERVICE);
...
}

Call this in your activity:

gps = new GPS(this, this);

Post a Comment for "Android Gps Not Working For Me"