简体   繁体   English

获取实际位置而不是模拟位置

[英]Get actual location rather than mocked location

Android has a option in developer options to mock location. Android在开发人员选项中提供了一个模拟位置的选项。 If my understanding is correct, if you set this location, the applications will start getting this location rather then the actual location? 如果我的理解是正确的,那么如果您设置此位置,应用程序将开始获取此位置,而不是实际位置?

If that is the case, how can we get the actual location regardless of what is set in this option? 如果是这样,无论此选项中设置了什么,我们如何获取实际位置?

If this is not the case, when is the mock location actually used (only in emulators?)? 如果不是这种情况,什么时候才实际使用模拟位置(仅在模拟器中使用?)?

As per my knowledge, we cant't get actual location if we are using MOKE location, 据我所知,如果使用的是MOKE位置,我们将无法获得实际位置,

Use of Moke location 使用Moke位置

Suppose you are developing a application in Australia region, and you want to test your application in USA environment (Location only) without going there, In that case we are using Moke location. 假设您正在澳大利亚地区开发应用程序,并且想在美国环境中(仅位置)测试应用程序,而无需前往那里,在这种情况下,我们将使用Moke位置。

I think location coming from android frameworks library , and these apis written is such a way, if you was set Moke location, then api will give priority to moke location only. 我认为位置来自android frameworks库,而编写的这些api就是这样一种方式,如果您设置了Moke位置,则api将仅优先于moke位置。 So if you want to use actual location you need to stop moke loaction. 因此,如果您想使用实际位置,则需要停止模拟运动。

You can write your own api which will directly talk to gps, then might be you will do it, But its major project itself 您可以编写自己的api,该API将直接与gps通讯,然后可能您会这样做,但是它的主要项目本身

EDIT 编辑

You can check MockSetting option is on or off 您可以检查“模拟设置”选项是打开还是关闭

/**
 *returns true if mock location enabled, false if not enabled.
**/
public static boolean isMockLocationStatus(Context context) {
  if (Settings.Secure.getString(context.getContentResolver(),
                                Settings.Secure.ALLOW_MOCK_LOCATION).equals("0"))
     return false;
  else
     return true;
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用LTE而不是WiFi获取位置数据时遇到问题 - Trouble getting location data using LTE rather than WiFi WSDL地址位置显示的是主机名,而不是本地主机 - Wsdl adress location is showing host name rather than localhost 引用数组中的位置而不是数组中的数据。 (Java) - Referencing a Location in an Array rather than the Data within it. (Java) 代码正在输出数组的位置,而不是数组本身 - code is outputting location of array rather than the array itself 在没有谷歌地图的情况下获取实际位置的纬度和日志 - Get Lat and Log of actual location without google maps 在地图上围绕当前位置绘制圆并仅显示该圆中的标记,而不显示android中的外圆 - Drawing Circle on Map around current location and showing only markers from that circle rather than outside circle in android Java Mockito正在使用真正的方法而不是使用模拟方法 - Java Mockito is hitting real method rather than using mocked method 获取JFrame的实际当前位置 - Getting a JFrame's actual current location 使用 fused Location Provider 获取当前位置 - Get current location with fused Location Provider 获取位置仅获取 UI 线程上的位置(GPS 位置) - Get Location only gets the location on UI Thread (GPS Location)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM