public NativeLocationSource(SourceCallback callback, Context context) { super(callback, context); mLocationManager = (LocationManager) getContext().getSystemService( Context.LOCATION_SERVICE); }
@Override public void onLocationChanged(final Location location) { handleMessage(new SimpleVehicleMessage(Latitude.ID, location.getLatitude())); handleMessage(new SimpleVehicleMessage(Longitude.ID, location.getLongitude())); }
@Override public void stop() { super.stop(); onPipelineDeactivated(); }
private void setNativeGpsStatus(boolean enabled) { Log.i(TAG, "Setting native GPS to " + enabled); if(enabled && mNativeLocationSource == null) { mNativeLocationSource = new NativeLocationSource(this); mPipeline.addSource(mNativeLocationSource); } else if(!enabled) { mPipeline.removeSource(mNativeLocationSource); mNativeLocationSource = null; } }
@Override public void run() { Looper.prepare(); // try to grab a rough location from the network provider before // registering for GPS, which may take a while to initialize Location lastKnownLocation = mLocationManager .getLastKnownLocation( LocationManager.NETWORK_PROVIDER); if(lastKnownLocation != null) { onLocationChanged(lastKnownLocation); } try { mLocationManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, NATIVE_GPS_UPDATE_INTERVAL, 0, this); Log.d(TAG, "Requested GPS updates"); } catch(IllegalArgumentException e) { Log.w(TAG, "GPS location provider is unavailable"); } mLooper = Looper.myLooper(); Looper.loop(); }