以下是我的代码:
private Location getLastKnownLoaction(boolean enabledProvidersOnly){
LocationManager manager = mActivityContext.getSystemService(Context.LOCATION_SERVICE);
Location location = null;
List<String> providers = manager.getProviders(enabledProvidersOnly)
for(String provider : providers){
location = manager.getLastKnownLocation(provider);
//maybe try adding some Criteria here
if(location != null) return location;
}
//at this point we've done all we can and no location is returned
return null;
}
我已经看到塔位置显示在较旧的诺基亚手机中.如何在Android中实现类似功能?“
最佳答案 确保你的清单上有这个
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
而且还必须在真实设备上尝试它而不是模拟器.