如何使用android找到最后的位置

时间:2015-09-16 12:13:11

标签: android gps locationmanager

我使用以下代码获取我最后知道的位置,但它无法正常工作

LocationManager locationManager = (LocationManager)getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteia();

String provider = locationManager.getBestProvider(criteria, true);
Location location = locationManager.getLastKnownLocation(provider);

if(location!=null){
    onLocationChanged(location);
}

locationManager.requestLocationUpdates(provider, 20000, 0, this);

1 个答案:

答案 0 :(得分:1)

很难说缺乏错误信息。只是一个猜测...你在AndroidManifest.xml中有这些:

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>