关于使用GPS获取当前位置出错的问题。
问题是这样的,小弟初学android,看着书本上的例子写了一段获取设备最后一次位置的程序,硬件设备是一台谷歌nexus7二代平板电脑,但是程序一直没有权限执行 getLastKnownLocation(sProvider); 这个方法,不知道哪里还需要配置一下,或者是我哪里传参数的时候传错了。。。麻烦大神帮我看看哦。
下面是我的一小段程序:
//声明一个位置管理器
LocationManager locationManager;
//位置管理器向系统请求位置服务
String sSvcName = Context.LOCATION_SERVICE;
locationManager = (LocationManager) getSystemService(sSvcName);
//指定GPS作为位置提供器
String sProvider = LocationManager.GPS_PROVIDER;
if (checkCallingPermission("android.permission.ACCESS_FINE_LOCATION") == PackageManager.PERMISSION_GRANTED)
{//校验是否有权限
//通过位置管理器获取位置
lMyLocation = locationManager.getLastKnownLocation(sProvider);
}