Belwo 是我用来在手机上获取位置更新的代码。当我在模拟器上运行它并从模拟器手动输入纬度和经度时,它可以正常工作,但是当我尝试在手机上运行这个应用程序时,它没有显示任何坐标。请帮忙..
清单文件具有所需的权限 -
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
我已检查并且 GPS 已打开我的手机
LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
LocationListener ll = new myLocationListener();
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,ll);
}
class myLocationListener implements LocationListener{
@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
if(location!=null)
{
double lo = location.getLongitude();
double la = location.getLatitude();
lati.setText(Double.toString(la));
longi.setText(Double.toString(lo));
}
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String provider, int status,
Bundle extras) {
// TODO Auto-generated method stub
}
}
}