我是Android的新手
我想在广播接收机中获取GPS位置,但它显示错误。
我的代码是:
public void onReceive(Context context, Intent intent) {
LocationManager locManager = (LocationManager)
getSystemService(Context.LOCATION_SERVICE);
// errors in getSystemService method
LocationListener locListener = new MyLocationListener();
locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,
locListener);
Location loc = locManager
.getLastKnownLocation(LocationManager.GPS_PROVIDER);
Log.d(" **location**", " location" + loc.getLatitude());
}
问题:
>是否可以在广播接收机中获取GPS定位数据?
>我迄今为止尝试的另一种替代方法是使用由Broadcast接收器调用的服务。该服务可以获取GPS数据,但如何在广播接收器中获取?