我试图使用Little Fluffy Location Library为了获取我的小应用程序的位置信息。我有它在异步过程中运行,如下所示:小毛茸茸的位置 - 误解如何获得当前位置
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);
}
}
}
我在我的onCreate()中调用它。
userLoc.execute();
我延伸我的应用程序与此类:
公共类FluffyLocation延伸申请{
@覆盖公共无效的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"); } }
}
设置的清单:
<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" />
我知道它正在运行,因为我得到的觥筹交错时显示信息活动运行...我正在尝试获取当前的loc每当用户打开应用程序时,我想我错过了这是如何工作的。我认为latestInfo.refresh()会给我最新的信息,但是,如果我移动到200米外的另一个位置,我仍然会得到相同的经纬度,并且也是相同的.lastLocationUpdateTimestamp。
我想获取当前用户位置,然后定期获取更新。这个库似乎是完美的,但是我没有得到结果。我没有正确实施?
编辑::::
我并没有实现广播接收器,但是,我不知道如何得到它超过一类的工作。我有3个不同的会要求用户的位置...