0
我想捕获没有GPS接收器芯片(或其GPS接收器芯片损坏的设备)的设备的位置坐标。 Android是否提供任何API来实现这一点。 A-GPS是否也指向相同的位置api?如何在没有GPS接收器芯片的情况下捕获位置坐标?
我想捕获没有GPS接收器芯片(或其GPS接收器芯片损坏的设备)的设备的位置坐标。 Android是否提供任何API来实现这一点。 A-GPS是否也指向相同的位置api?如何在没有GPS接收器芯片的情况下捕获位置坐标?
使用网络供应商,而不是GPS某些选项
您可以使用网络提供商,而不是,下面我张贴这为我工作的代码。
它检查:第一,它提供可用,并选择它。因此,根据您的优先级,你可以编辑代码选择网络或GPS
public Location getLocation() {
try {
locationManager = (LocationManager) mContext
.getSystemService(LOCATION_SERVICE);
// getting GPS status
isGPSEnabled = locationManager
.isProviderEnabled(LocationManager.GPS_PROVIDER);
// getting network status
isNetworkEnabled = locationManager
.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if (!isGPSEnabled && !isNetworkEnabled) {
// no network provider is enabled
} else {
this.canGetLocation = true;
if (isNetworkEnabled) {
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
Log.d("Network", "Network Enabled");
if (locationManager != null) {
location = locationManager
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
}
}
}
// if GPS Enabled get lat/long using GPS Services
if (isGPSEnabled) {
if (location == null) {
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
Log.d("GPS", "GPS Enabled");
if (locationManager != null) {
location = locationManager
.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
}
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return location;
}
调用你想要的方式明智。
您应该移除“GPS位置”中的“GPS”.-因此,您需要位置坐标而无需GPS接收器。 – AlexWien
是的,谢谢你的建议 – John