GPS

Wingnut

Well-known member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
1,229
I'm trying to get GPS working on Android but I'm stuck with a compilation error?

'' ..GPS/gps.buildv2021-03-21/android/app/src/main/java/com/cerberus/cerberusgame/CerberusGame.java:2895: error: package cerberusGame does not exist
' cerberusGame.activity.runOnUiThread(New Runnable() {
' ^
'...GPS/gps.buildv2021-03-21/android/app/src/main/java/com/cerberus/cerberusgame/CerberusGame.java uses unchecked Or unsafe operations.

gps.cxs
Code:
Strict
Import mojo
Import "gps.java"
#ANDROID_MANIFEST_MAIN+="<uses-permission android:name=~qandroid.permission.ACCESS_FINE_LOCATION~q />"

Extern

Function StartGps:Void()="external.startGps"
Function GetLatitiude:String()="external.getLatitiude"
Function GetLongitude:String()="external.getLongitude"

' Try floats instead of strings
' Function StartGps:Void()="external.startGps"
' Function GetLatitiude:Float()="external.getLatitiude"
' Function GetLongitude:Float()="external.getLongitude"

Public

Global myGame:MyGame

Function Main:Int()
    myGame = New MyGame
    Return 0
End

Class MyGame Extends App

    Method OnCreate:Int()
        SetUpdateRate 0
        StartGps()
        Return 0  
    End
   
    Method OnRender:Int()
        Cls
        ' DrawText GetLatitiude(),0,20
        ' DrawText GetLongitude().,0,40
        Return true
    End

End Class

gps.java
Code:
import android.location.LocationManager;
import android.location.LocationListener;
import android.location.Location;

class external
{
    public static LocationManager myManager;
    public static String latitude;
    public static String longitude;
    // public static float latitude;
    // public static float longitude;

    public static boolean gpsStarted = false;

    static void startGps()
    {
    try {
    myManager = (LocationManager)cerberusGame.activity.getSystemService(Context.LOCATION_SERVICE);

    final LocationListener locationListener = new LocationListener() {
    public void onLocationChanged(Location location) {
    latitude = String.format("%.6f", location.getLatitude());
    longitude = String.format("%.6f", location.getLongitude());
    // latitude = location.getLatitude() + "";
    // longitude = location.getLongitude() + "";
    // latitude = (float)location.getLatitude(); // try floats instead...
    // longitude = (float)location.getLongitude(); // ...of strings

    }
    public void onStatusChanged(String provider, int status, Bundle extras) {}
    public void onProviderEnabled(String provider) {}
    public void onProviderDisabled(String provider) {}
    };

    cerberusGame.activity.runOnUiThread(new Runnable() {
    public void run() {
    try {
    if (!gpsStarted) {
        myManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
        gpsStarted = true;
    }
    }catch (java.lang.SecurityException e) {
    android.util.Log.e("[cerberus]", "SecurityException: " + android.util.Log.getStackTraceString(e));
    }
    }
    });
    } catch (java.lang.SecurityException e) {
    android.util.Log.e("[cerberus]", "SecurityException: " + android.util.Log.getStackTraceString(e));
    }
    }
    static String getLatitiude() {
        return latitude;  
    }
    static String getLongitude() {
        return longitude;
    }

}
 
Last edited:

MikeHart

Administrator
3rd Party Module Dev
3rd Party Target Dev
3rd Party Tool Dev
Joined
Jun 19, 2017
Messages
3,390
Maybe

CerberusGame

instead of

cerberusGame

?
 

Wingnut

Well-known member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
1,229
No sadly that didn't fix it, but that's one thing for sure. I'll try to dig into this later as my Android skills are severely lacking at this stage I need to brush them up first.
 
Top Bottom