如何在Android中获取移动设备的纬度和经度?如何使用定位工具获取Android中移动设备的当前纬度和经度?
3 回答
阿晨1998
TA贡献2037条经验 获得超6个赞
LocationManager.
LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE); Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); double longitude = location.getLongitude();double latitude = location.getLatitude();
getLastKnownLocation()nullLocationListenerrequestLocationUpdates()
private final LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
longitude = location.getLongitude();
latitude = location.getLatitude();
}}lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 10, locationListener);ACCESS_FINE_LOCATION
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
ACCESS_COARSE_LOCATIONgetBestProvider()
添加回答
举报
0/150
提交
取消
