为什么不能在Android模拟器的工作与地理位置本土作出反应?

问题描述 投票:0回答:2

我试图让Android的当前用户位置与之反应原住民。我已经写在App.js文件下面的代码片段:

import React, { Component } from "react";
import {
  Platform,
  StyleSheet,
  Text,
  View,
  Alert,
  TouchableOpacity
} from "react-native";

export default class App extends Component {
  state = {
    location: null
  };

  findCoordinates = () => {
    navigator.geolocation.getCurrentPosition(
      position => {
        const location = JSON.stringify(position);

        this.setState({ location });
      },
      error => alert(error.message),
      { enableHighAccuracy: true, timeout: 20000, maximumAge: 1000 }
    );

    alert("SKIPPED");
  };

  render() {
    return (
      <View style={styles.container}>
        <TouchableOpacity onPress={this.findCoordinates}>
          <Text style={styles.welcome}>Find My Coords?</Text>
          <Text>Location: {this.state.location}</Text>
        </TouchableOpacity>
      </View>
    );
  }
}


const styles = StyleSheet.create({
  ... some style ...
});

由于我使用的Android模拟器,我还增加了在位于AndroidManifest.xmlandroid\app\src\main文件中的以下行,只是application标签上面:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

当我运行它,分享GPS位置没有请求弹出,也是getCurrentPosition功能似乎只是跳过。出现状态不更新,不显示任何错误和警告“跳过”了。

这就是我在屏幕上看到的“跳过”了警报驳回后:

enter image description here

我缺少的是在这里吗?

android react-native geolocation
2个回答
0
投票

IOS

如果你正在使用模拟器适用于iOS,去模拟器的菜单栏中选择Debug‣位置‣自定义位置。进入A坐标的经度和纬度。

Android的

如果您使用的是Android的虚拟设备,单击三个点,代表扩展的控制,在仿真器工具栏上。在位置部分,输入坐标的经度和纬度。


0
投票

显然,我不得不重新启动我的模拟器,然后它开始正常工作。发现一个提示here

© www.soinside.com 2019 - 2024. All rights reserved.