Skip to content

Instantly share code, notes, and snippets.

@cbaggers
Last active August 29, 2015 14:08
Show Gist options
  • Save cbaggers/5b4d4b94fa05bb8aacd3 to your computer and use it in GitHub Desktop.
Save cbaggers/5b4d4b94fa05bb8aacd3 to your computer and use it in GitHub Desktop.
GPS in Uno
using Uno;
using Uno.Platform;
using Uno.Collections;
using Android;
using Android.Runtime;
using Android.android.os;
using Android.android.app;
using Android.android.content;
using Android.android.location;
namespace GPS
{
public class LocListen : Android.java.lang.Object, LocationListener
{
LocationManager lm;
public LocListen()
{
var activity = Activity.GetAppActivity();
lm = (LocationManager)activity.getSystemService(Context.LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
}
public void onLocationChanged(Location location)
{
// Called when the location has changed.
debug_log "got a location: "+location.getLatitude()+","+location.getLongitude();
}
public void onProviderDisabled(Android.java.lang.String provider)
{
// Called when the provider is disabled by the user.
debug_log "disabled";
}
public void onProviderEnabled(Android.java.lang.String provider)
{
// Called when the provider is enabled by the user.
debug_log "enabled";
}
public void onStatusChanged(Android.java.lang.String provider, int status, Bundle extras)
{
// Called when the provider status changes.
debug_log "status changed";
}
}
public class GPS : Uno.Application
{
static int id = 0;
LocationListener ll;
bool started = false;
Android.java.lang.Runnable runnable;
public GPS()
{
Uno.Application.Current.Window.PointerPressed += Press;
}
public void Press(object sender, Uno.Platform.PointerEventArgs args)
{
if (!started) {
started = true;
runnable = UnoHelper.RunnableFromAction(StartGPS);
Activity.GetAppActivity().runOnUiThread(runnable);
}
}
public void StartGPS()
{
ll = new LocListen();
}
public override void Draw()
{
ClearColor = float4(0, 0, 1, 1);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment