简体   繁体   English

即使LocationServices已关闭,也要获取位置

[英]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.

相关问题 即使使用融合位置 API 关闭 GPS,如何获取位置更新? - How to get Location updates even when gps is turned off using fused location API? 如果位置已从设置中关闭,则获取位置 - get location if the location is turned off from settings 即使在用户强行关闭gps的情况下,如何使用fusionloaction api在后台获取位置信息? - How to get location information in background using fusedloaction api even when gps is turned off forcefully by the user? 即使Android 4.4.2中的位置服务已关闭,GetCurrentLocation仍在使用Cordova / PhoneGap App - GetCurrentLocation is working on Cordova/PhoneGap App even when the Location services are turned off in Android 4.4.2 android LocationServices Api在后台时未获取位置更新 - android LocationServices Api not getting location updates when in background android检查用户是否关闭了位置 - android check if user turned off location 如何检测用户是否在设置中关闭了位置? - How to detect if user turned off Location in Settings? 关闭GPS的位置查找方法 - A way to find location with GPS turned off 位置打开/关闭时,FusedLocationProviderClient 无法正常工作 - FusedLocationProviderClient not working correctly when Location turned on/off 即使关闭屏幕也可以开始活动 - Start activity even when screen is turned off
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM