Android 安卓经纬度
我正在开发一个应用程序,它必须找到用户位置的纬度和长度,然后显示在地图上。但是,当设备上有互联网时,它工作正常。但是,当我尝试断开互联网后,它会变为lat和long null 查询:Android 安卓经纬度,android,Android,我正在开发一个应用程序,它必须找到用户位置的纬度和长度,然后显示在地图上。但是,当设备上有互联网时,它工作正常。但是,当我尝试断开互联网后,它会变为lat和long null 查询: 如果我想找到lat和long程序,互联网连接应该在那里吗 没有连接到internet,我能找到lat和long程序吗 通过实现LocationListener和 大概是这样的: LocationManager locmgr = (LocationManager) getSystemService(Context.L
通过实现
LocationListener
和
大概是这样的:
LocationManager locmgr = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locmgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); //"this" implements LocationListener
@Override
public void onLocationChanged(Location location) {
//do whatever with "location"
}
根本不需要互联网连接,你只需要一个位置提供商(a-GPS,GPS)事实上,Android有两种方法来确定你的经度/纬度
- 如果GPS被激活,它将使用GPS
- 如果没有,它将根据您所在的小区或ip地址,使用网络(或wifi)来确定
因此,如果GPS被禁用(或由于在室内或恶劣的气象条件而无法捕获信号),并且网络也不正常,Android将无法计算您的坐标。如果您想在地图上显示,请使用MyLocationOverlay。这比实现自己的locationListeners更容易。调用enableMyLocation onResume()和disableMyLocation onPause()
您还可以将MyLocationOverlay子类化,以更改图标、在位置更改时执行自定义操作等。应添加GPS可能已激活,但没有来自卫星的信号(例如天空多云)。