【发布时间】:2013-12-13 13:15:30
【问题描述】:
我有一个使用 Google 地图和新的 Fuse Location API 的应用。当位置更改时,我使用此代码获取更新:
locationClient.requestLocationUpdates(new LocationRequest(),
new LocationListener() {
@Override
public void onLocationChanged(Location location) {
//Some code
}
});
我在装有 Android 4.3 的 Galaxy Nexus 上没有问题。但是,在我朋友的装有 Android 4.0.4 的手机 (Xperia ST21i) 中,我无法收到这些更新。
我在 Android 文档和 StackOVerflow 上的许多(如果不是全部)问题上看到使用 LocationRequest.create() 而不是 new LocationRequest()。这个新代码在我的手机上仍然可以正常工作;我还没有在朋友的手机上试过。
阅读文档,我猜LocationRequest.create() 是这样的:
public static LocationRequest create() {
LocationRequest locationRequest= new LocationRequest();
locationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
locationRequest.setFastestInterval(aNumber);
locationRequest.setInterval(anotherNumber);
return locationRequest;
}
这两段代码有什么区别,为什么它可以在我的手机上运行,但在我朋友的手机上却不行。在我朋友的手机上更改后它会起作用吗?
如果没有,我还需要做什么才能使其正常工作?
【问题讨论】:
-
LocationRequest.create()只是返回new LocationRequest()。那里没有额外的魔法。 -
aw :/ 这对我来说是个坏消息,因为现在我不知道为什么它在我朋友的手机上不起作用。他激活了gps和wifi。位置服务没有被禁用,因为他拥有最新版本的谷歌地图,并且可以毫无问题地使用它。我真正的问题是,如果我找不到任何解决方案,
locationClient.getLastLocation()将始终返回 null。
标签: android google-maps location google-maps-android-api-2 google-play-services