简体   繁体   English

React Native App 没有从 Android Emulator 获取位置

[英]React Native App is not getting location from Android Emulator

First of all I'll let you know that this question solves a part of my problem but not all of it:首先,我会让你知道这个问题解决了我的部分问题,但不是全部:

Emulator's Location simulation not working 模拟器的位置模拟不起作用

I managed to have the emulator's location provider to work (verifying it using the Google Maps App) but it is my React Native app the one that is not getting the location.我设法让模拟器的位置提供程序工作(使用谷歌地图应用程序验证它),但我的 React Native 应用程序没有获得位置。 It does on a real device so I would say it is more of an issue between the app and the emulator.它在真实设备上运行,所以我想说这更多是应用程序和模拟器之间的问题。

So as I said, I'm getting this location in the Google Maps App:所以正如我所说,我在谷歌地图应用程序中得到了这个位置:

在此处输入图像描述

My Emulator specs:我的模拟器规格:

在此处输入图像描述

What I'm doing in my React App is the following:我在我的 React App 中所做的如下:

In a React async action: (Works on real device)在 React 异步操作中:(适用于真实设备)

return navigator.geolocation.getCurrentPosition(
  (position) => {
    let initialCenterPosition = {
      latitude : position.coords.latitude,
      longitude : position.coords.longitude
    }

    dispatch(requestInitialCenterPositionSuccess(initialCenterPosition))
  },
  (error) => {
    dispatch(requestInitialCenterPositionError(error))
  },
  {enableHighAccuracy: true, timeout: 10000, maximumAge: 0}
)

And the current permissions in my Android Manifest XML just in case:我的 Android Manifest XML 中的当前权限以防万一:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

My Sdk and Build Tools versions in the build.graddle file: build.graddle 文件中的我的 Sdk 和 Build Tools 版本:

compileSdkVersion 23
buildToolsVersion "23.0.3"

Also tested it with builtToolsVersion : "24.0.2"还使用 builtToolsVersion 对其进行了测试:“24.0.2”

Switching the enableHighAccuracy to false in the getCurrentPosition function won't do any change.在 getCurrentPosition 函数中将 enableHighAccuracy 切换为 false 不会做任何改变。

Is there another aspect I should be aware off in my React Native app specs so this could work?在我的 React Native 应用程序规范中,我是否应该注意另一个方面,以便它可以工作? It does seem weird to me that I don't have any trouble on the real device对我来说,我在真实设备上没有任何问题似乎很奇怪

Thanks to all谢谢大家

设置为enableHighAccuracy false,问题就解决了

{enableHighAccuracy: false, timeout: 10000, maximumAge: 0}

更改位置设置后,您应该在设备中重新启动。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM