我发送一个字符串额外的麻烦PendingIntent,我传递给我LocationServices.FusedLocationApi.requestLocationUpdates(GoogleApiClient client, LocationRequest request, PendingIntent callbackIntent).
看来,我正在加入的用户名Intent正在破坏requestLocationUpdates试图交给我IntentService作为intent.getParcelableExtra(FusedLocationProviderApi.KEY_LOCATION_CHANGED)回报的位置null.
编辑
我已经尝试创建一个User实现Parcelable并将其作为额外的类:
mRequestLocationUpdatesIntent.putExtra("username", new User(username));
Run Code Online (Sandbox Code Playgroud)
我还尝试通过此错误报告https://code.google.com/p/android/issues/detail?id=81812中的评论建议将Parcelable User内部设置Bundle为内置:
Bundle userBundle = new Bundle();
userBundle.putParcelable("user", new User(username));
mRequestLocationUpdatesIntent.putExtra("user", userBundle);
Run Code Online (Sandbox Code Playgroud)
在我的服务中:
Bundle userBundle = intent.getBundleExtra("user");
User user = userBundle.getParcelable("user");
String username = user.getUsername();
Run Code Online (Sandbox Code Playgroud)
然而,这些方法都没有任何区别.每当我对我的意图添加任何额外内容时,在更新发生时,该位置永远不会添加到意图中.
我设置此IntentService处理位置更新:
public class LocationUpdateService extends IntentService {
private final String TAG = "LocationUpdateService";
public LocationUpdateService() { …Run Code Online (Sandbox Code Playgroud) android android-intent android-location google-play-services fusedlocationproviderapi
我正在使用Fused location Api,我的位置精度约为10米.有时它可以提供4到8米的精度.我希望使用这个融合位置Api或任何其他方式更准确.有没有办法获得精度低于4米的位置.
我正以这种方式获得位置.
public class GetCurrentLocation implements
ConnectionCallbacks, OnConnectionFailedListener, LocationListener {
private static final String TAG = "location-updates-sample";
public static final long UPDATE_INTERVAL_IN_MILLISECONDS = 0;
public static final long FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS =
UPDATE_INTERVAL_IN_MILLISECONDS / 2;
private final String REQUESTING_LOCATION_UPDATES_KEY = "requesting-location-updates-key";
private final String LOCATION_KEY = "location-key";
private final String LAST_UPDATED_TIME_STRING_KEY = "last-updated-time-string-key";
private GoogleApiClient mGoogleApiClient;
private LocationRequest mLocationRequest;
private Context mContext;
private getLocation mGetCurrentLocation;
public GetCurrentLocation(Context context) {
mContext = context;
buildGoogleApiClient();
}
private synchronized void buildGoogleApiClient() {
Log.i(TAG, …Run Code Online (Sandbox Code Playgroud) android google-maps fusedlocationproviderapi android-fusedlocation
我正在调试一个位置感知应用程序,我想得到一个当前正由系统监控的Geofences列表 - 即使我只能看到我自己的软件包的Geofences.代码使用的是GoogleApiClient,因此使用了FusedLocation.
我试过adb shell dumpsys location哪个有"Geofences:"的输出部分,但它总是空的.我假设这是遗留位置/地理围栏/邻近.
我也尝试过只adb shell dumpsys搜索该文件以获取地理围栏,但我一无所获.
这两个命令都是在启动应用程序并成功添加要监视的栅栏后运行的.可以在此处找到实现的示例:https://github.com/androidfu/GeofenceExample
每隔一段时间我就得到:
不幸的是,MyApp已经停止了.
如果您有一些日志,问题很容易解决,但在我的情况下,logcat绝对没有错误消息(它有我的应用程序发布的正常消息,其他异常显示在那里但不是这导致这个app has stopped).
我有没有机会解决这个问题?
好处是我可以很容易地重现它,因此我试图将尽可能多的信息放入logcat然后调查发生了什么.
我已经启动并运行了ACRA(其他例外是由它捕获但不是这个app has stopped).
当它发生时我的应用程序不可见,并且在IntentService中有一些事情发生.我的应用程序正在跟踪地理围栏,app has stopped当我在手机设置中打开和关闭位置时,仅在HTC M8上发生.我已经在不同的手机上进行了测试,并且不会发生在LG G3,Nexus 5,Moto G,LG Swift L9上.
在我们的应用程序中,我们使用融合位置提供程序(FLP)来跟踪位置.我们注意到,应用程序偶尔会进入一个状态,其中位置回调停止被调用.该应用程序主要用于两个平板电脑(nexus 7和LG G-pad 8.3).我们已经看到两个设备都出现了这个问题.通常,重置设备似乎可以缓解这个问题.我们相信我们遵循大多数使用FLP的最佳实践.但是,万一我们将这个示例代码放在一起,说明了我们如何使用FLP.
获取谷歌API客户端并致电连接:
m_googleApiClient = builder
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
m_googleApiClient.connect()
Run Code Online (Sandbox Code Playgroud)
连接后,我们开始侦听位置回调:
@Override
public void onConnected(Bundle bundle) {
m_fusedLocationProviderApi.requestLocationUpdates(m_googleApiClient, m_locationRequest, this);
}
Run Code Online (Sandbox Code Playgroud)
位置请求如下所示:
LocationRequest locationRequest = LocationRequest.create();
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
locationRequest.setInterval(UPDATE_INTERVAL_IN_MILLISECONDS);
locationRequest.setFastestInterval(FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS);
Run Code Online (Sandbox Code Playgroud)
然后我们像这样实现回调:
@Override
public void onLocationChanged(Location location) {
// set location member var and record timestamp.
}
Run Code Online (Sandbox Code Playgroud)
当问题发生时,我们似乎没有得到任何错误回调.当我们检测到我们在很长一段时间内没有收到GPS时,我们也尝试在google api客户端上调用reset().我们还每2秒使用一个计时器监控位置可用性(使用getLocationAvailability).通常我们发现让用户重置其设备(开机,关机)可以解决问题.
我们的问题是:
gps android google-play-services location-services fusedlocationproviderapi
我在我的应用程序中使用融合位置提供程序,设置PRIORITY_HIGH_ACCURACY间隔为60秒.这通常有效,但有时位置本身不会更新5到10分钟,而当我打开谷歌地图时,它似乎会触发位置更新.
这里的任何其他人可能遇到过这个问题,或者知道这种行为背后的可能原因?有没有什么办法解决这一问题?
我正在使用LocationServices.FusedLocationApi以给定的时间间隔获取位置更新,该时间间隔是在传递给requestLocationUpdates的LocationRequest对象上设置的:
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(30000);
LocationServices.FusedLocationApi.requestLocationUpdates(
mGoogleApiClient, mLocationRequest, this);
Run Code Online (Sandbox Code Playgroud)
我需要在侦听器开始接收位置更新后更改间隔的值.这样做的正确方法是什么?
我正在尝试创建一个服务,每隔x秒和距离后接收位置更新.我在x秒后收到更新,但从未离开y距离.我用不同的值多次测试它,似乎setSmallestDisplacement根本不起作用.有关此事的各种帖子,但没有任何解决方案.如果有人可以帮助我,甚至指向不同的方向,我将不胜感激.
我的服务
public class GPS_Service extends Service implements GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener, LocationListener {
private GoogleApiClient mGoogleApiClient;
private LocationRequest mLocationRequest;
private int timethresh;
private int distancethresh;
protected Location mCurrentLocation;
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(LocationServices.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
mGoogleApiClient.connect();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
mLocationRequest = new LocationRequest();
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
//Set the desired interval for active location updates, in milliseconds.
mLocationRequest.setInterval(60* 1000);
//Explicitly …Run Code Online (Sandbox Code Playgroud) android google-play-services fusedlocationproviderapi android-fusedlocation
在我的服务中,我已将FusedLocation请求位置设置为将位置发送到静态BroadcastReceiver
public static class LocationReceiver extends BroadcastReceiver {
private String TAG = this.getClass().getSimpleName();
private LocationResult mLocationResult;
@Override
public void onReceive(final Context context, Intent intent) {
try {
Log.d("Test", "has result = " + LocationResult.hasResult(intent));
...
Run Code Online (Sandbox Code Playgroud)
在我们的崩溃报告中,我们有许多Anroid 4.4.2用户(但不是所有用户而不是所有时间......),其中LocationResult.hasResult(intent); 抛出一个
java.lang.RuntimeException:parcel android.os.Parcel@2ea0e34c:在android.os.Parcel.readArrayMapInternal(Parcel.java)的android.os.Parcel.readValue(Parcel.java:2080)的偏移248处解组未知类型代码7274595 :2314)在android.os.Bundle.unparcel(Bundle.java:249)的android.os.Bundle.containsKey(Bundle.java:299)在android.content.Intent.hasExtra(Intent.java:4443)的com .google.android.gms.location.LocationResult.hasResult(未知来源)
我没有任何4.4.2设备,在模拟器上我无法重现/不知道如何重现或是什么原因引起的?
有人已经看过了吗?我应该试试吗?
android location unmarshalling parcel fusedlocationproviderapi
我正在尝试使用 FusedLocationProviderClient 和 Kotlin 协程请求一个新位置。这是我目前的设置:
class LocationProviderImpl(context: Context) : LocationProvider, CoroutineScope {
private val TAG = this::class.java.simpleName
private val job = Job()
override val coroutineContext: CoroutineContext
get() = job + Dispatchers.IO
private val fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(context)
private val locationRequest = LocationRequest().apply {
numUpdates = 1
priority = LocationRequest.PRIORITY_HIGH_ACCURACY
}
override suspend fun getLocation(): LatLng = suspendCoroutine {
val locationCallback = object : LocationCallback() {
override fun onLocationResult(result: LocationResult) {
result.lastLocation.run {
val latLng = latitude at longitude
it.resume(latLng)
}
fusedLocationProviderClient.removeLocationUpdates(this) …Run Code Online (Sandbox Code Playgroud) android ×10
gps ×2
acra ×1
adb ×1
exception ×1
geofencing ×1
google-maps ×1
kotlin ×1
location ×1
parcel ×1