[英]Getting the Location even if LocationServices is turned off
In Android if LocationServices is disabled, is there any way that I can get the current location through wifi/network . 在Android中,如果LocationLocations被禁用,有什么方法可以通过wifi / network获取当前位置。 I know there is one way of showing the user a popup to change his LocationSettings , but I don't want to show the popup.
我知道有一种向用户显示弹出窗口以更改其LocationSettings的方法,但是我不想显示该弹出窗口。
So is there any way of getting the current location even if LocationServices is disabled ? 那么,即使禁用了LocationServices,也有什么方法可以获取当前位置?
use LocationManager.NETWORK_PROVIDER
instead of LocationManager.GPS_PROVIDER
使用
LocationManager.NETWORK_PROVIDER
而不是LocationManager.GPS_PROVIDER
The entire code and how to use is given here : http://developer.android.com/guide/topics/location/strategies.html 此处提供了完整的代码及其用法: http : //developer.android.com/guide/topics/location/strategies.html
// Acquire a reference to the system Location Manager
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
// Define a listener that responds to location updates
LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
// Called when a new location is found by the network location provider.
makeUseOfNewLocation(location);
}
public void onStatusChanged(String provider, int status, Bundle extras) {}
public void onProviderEnabled(String provider) {}
public void onProviderDisabled(String provider) {}
};
// Register the listener with the Location Manager to receive location updates
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
Yes of course, you can use: 是的,当然可以使用:
// let Android select the right location provider for you
String myProvider = locationManager.getBestProvider(myCriteria, true);
check this for more details good-way-of-getting-the-users-location-in-android and this Location Strategies 检查此以获得更多详细信息,了解如何在Android中获取用户位置以及此位置策略
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.