I am attempting to use the Little Fluffy Location Library in order to get location information for my little app. I have it running in an async process like so:
private class ShowLocationTask extends AsyncTask<Void, Void, Boolean> {
@Override
protected Boolean doInBackground(Void... params) {
//LocationLibrary.forceLocationUpdate(getApplicationContext());
latestInfo = new LocationInfo(getBaseContext());
latestInfo.refresh(getBaseContext());
lat = latestInfo.lastLat;
lng = latestInfo.lastLong;
return true;
}
protected void onPostExecute(Boolean result) {
if (result != true) {
Toast.makeText(ACTIVITY.this,
"Cannot get your location...", Toast.LENGTH_LONG)
.show();
} else {
Date date = new Date(latestInfo.lastLocationUpdateTimestamp);
Toast.makeText(ACTIVITY.this,
"Last Updated: " + date, Toast.LENGTH_LONG).show();
LatLng meLoc = new LatLng(lat, lng);
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(meLoc) // Sets the center of the map to
.zoom(ZP).bearing(0).tilt(80).build();
map.animateCamera(CameraUpdateFactory
.newCameraPosition(cameraPosition));
Toast.makeText(ACTIVITY.this,
"..." + lat + " : " + lng, Toast.LENGTH_LONG).show();
Log.e("LATLON", lat + " : " + lng);
}
}
}
I call that in my onCreate().
userLoc.execute();
I extend my application with this class:
public class FluffyLocation extends Application {
@Override public void onCreate() { super.onCreate();
LocationLibrary.showDebugOutput(true); try { LocationLibrary.initialiseLibrary(getBaseContext(), 0, 2 * 60 * 1000, "com.jasonflaherty.snoteldata"); } catch (UnsupportedOperationException ex) { Log.d("Application", "UnsupportedOperationException thrown - the device doesn't have any location providers"); } }
}
Setup in the Manifest:
<receiver android:name="com.littlefluffytoys.littlefluffylocationlibrary.StartupBroadcastReceiver" android:exported="true" > <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> </receiver> <receiver android:name="com.littlefluffytoys.littlefluffylocationlibrary.PassiveLocationChangedReceiver" android:exported="true" />
I know it is running, since I get the TOAST to show info each time the activity runs... I am trying to get the current location each time the user opens the app. I guess I am missing how this works. I was thinking the latestInfo.refresh() would give me the latest info, however, if I move to another location 200 meters away, I still get the same lat/lng and also the same .lastLocationUpdateTimestamp.
I would like to get the current user location and then periodically get an update. This library seems perfect for that reason... but I am not getting the results. Am I not implementing this correctly?
EDIT::::
I didn't implement the broadcast receiver, however, I am not sure how to get it to work for more than one class. I have 3 different ones that would ask for the users location...
the refresh() method just update the current latestInfo objet. you need ask for update.
and you need let libary a secconds for get the current location. then you can call
and show.
implementing the a Broadcast for the library let you access to the method OnLocationChanged, who is called when the LocationListenner of the library get a new location.
and in the manifest file you have to define this receiver