Since I'm struggling arround with the integration of GPS functionality, I decided to create a step by step tutorial on the GPS subject, since I think, that there are more AppGameKit users out there with the same demand....
I didn't managed it yet to get it working, but I think I'm pretty close to the android solution. That's why I need some help now from experienced AppGameKit users
I base the tutorial on Pauls rough idea how to integrate GPS into a Tier1 android app:
You will need to find a Java example of getting a GPS location, this should be well documented. Next you will need to edit AGKHelper.java by adding your GPS code as functions you can easily use to get the location data you want, for example you could add a function GetLatitude or something, add them to the "public class AGKHelper" section. Now comes the hacking, in order to get your GPS data back into AppGameKit I recommend hijacking some functions you are not using. The video commands look ideal for this, particularly GetVideoPlaying, GetVideoWidth, etc. Find the function GetVideoValue inside AGKHelper.java and modify the switch statement to return your GPS values based on which value you want to return for each function, and clear out any video code in this function. You can then use the AppGameKit video functions to access these values. If you need to do any GPS setup, stick it in the "public static void OnStart( Activity act )" function.
So I'm going to add the GPS functionality by adding JAVA code to the AGKHelper.java section. At the end I want to extract latitude and longitude values by hijacking the
getVideoHeight() and
getVideoWidth() functions.
But at first, I gave the app the rights to use GPS with following line in the
AndroidManifest.xml :
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Then I added following JAVA code to the import segment:
import android.app.Service;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.IBinder;
import android.provider.Settings;
After that I added:
class AGKGPS extends Activity {
/** Called when the activity is first created. */
private LocationManager lm;
private LocationListener locationListener;
public double mLongitude = 0;
public double mLatitude = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
locationListener = new MyLocationListener();
lm.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
500, // ms since last call
10, // 10 m movement
locationListener);
}
public class MyLocationListener implements LocationListener
{
public void onLocationChanged(Location loc) {
if (loc != null) {
mLongitude = loc.getLongitude();
mLatitude = loc.getLatitude();
}
}
public void onProviderDisabled(String provider) {
//
}
public void onProviderEnabled(String provider) {
//
}
public void onStatusChanged(String provider, int status, Bundle extras) {
}
}
}
And send the longitude and latitude values to the app by hijacking the following video functions:
public static float GetVideoValue( Activity act, int value )
{
/*
if ( RunnableVideo.video == null ) return videoLoaded==1 ? 0 : -1;
if ( RunnableVideo.video.m_filename == "Error" ) return -1;
if ( RunnableVideo.video.m_filename == "" ) return videoLoaded==1 ? 0 : -1;
*/
switch(value)
{
case 1: // video position
{
return 0;
}
case 2:
{
return 0;
}
case 3:
{
return (float) AGKGPS.mLongitude; // video width
}
case 4:
{
return (float) AGKGPS.mLatitude; // video height
}
}
return 0;
}
But unfortunately it's not working. As soon as the app tries to recieve the values from the GETVIDEOHEIGHT or GETVIDEOWIDTH function, screen becomes blank and after a few seconds the app stops working.
Would be great if some one could check the way I went above and check for errors. Would be great if we could get it working today so we could add the iOS solution for GPS too then....
Thanks in advance!