Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

大佬 RN0.61.3版本定位没反应呀 是不支持吗? #109

Closed
wuzh1993 opened this issue Nov 21, 2019 · 2 comments
Closed

大佬 RN0.61.3版本定位没反应呀 是不支持吗? #109

wuzh1993 opened this issue Nov 21, 2019 · 2 comments
Labels
android Only for android bug Something isn't working

Comments

@wuzh1993
Copy link

wuzh1993 commented Nov 21, 2019

为了节省大家的时间,请尽可能详细地说明问题,并最好提供截图(特别是出错信息)。
async componentDidMount() {
// 对于 Android 需要自行根据需要申请权限
await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION);
// 使用自己申请的高德 App Key 进行初始化
await init({
android: "eb09390e79f2d193b680752576045041"
});
Geolocation.getCurrentPosition(({ coords }) => {
console.log(1223)
console.log(coords);
});
}

已经解决 是自己的问题

@wuzh1993 wuzh1993 added android Only for android bug Something isn't working labels Nov 21, 2019
@Dobyc
Copy link

Dobyc commented Nov 21, 2019

我是0.61.2, 同样也是没有反应,也不报错
`
import React, { Component } from 'react'
import { connect } from 'react-redux'
import { SafeAreaView } from 'react-native'
import { PermissionsAndroid } from "react-native";
import { init, Geolocation, setNeedAddress } from "react-native-amap-geolocation";

export class DeviceAdd extends Component {
constructor(props){
super(props);
}

componentDidMount() {
    this._getLocation();
}

async _getLocation() {
    let granted = await PermissionsAndroid.request(
        PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION,
    
        {
          title: "本应用需要使用定位权限",
          message: "需要您打开GPS,然后就可以顺利找到加油站啦!",
          buttonNeutral: "让我再想想",
          buttonNegative: "不行",
          buttonPositive: "打开GPS"
        }
      );
    if (granted === PermissionsAndroid.RESULTS.GRANTED) {
        await init({
          android: "****"
        });
        setNeedAddress(true);
    
        await Geolocation.getCurrentPosition(({ coords }) => {
          //console.log(coords);
          AsyncStorage.setItem("LAT", `${coords.latitude}`);
          AsyncStorage.setItem("LNG", `${coords.longitude}`);
        }, error => console.error(error));
      }
}

render() {
    return (
        <SafeAreaView></SafeAreaView>
    )
}

}

const mapStateToProps = (state) => ({

})

const mapDispatchToProps = {

}

export default connect(mapStateToProps, mapDispatchToProps)(DeviceAdd)
`

@wuzh1993
Copy link
Author

我是0.61.2, 同样也是没有反应,也不报错
`
import React, { Component } from 'react'
import { connect } from 'react-redux'
import { SafeAreaView } from 'react-native'
import { PermissionsAndroid } from "react-native";
import { init, Geolocation, setNeedAddress } from "react-native-amap-geolocation";

export class DeviceAdd extends Component {
constructor(props){
super(props);
}

componentDidMount() {
    this._getLocation();
}

async _getLocation() {
    let granted = await PermissionsAndroid.request(
        PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION,
    
        {
          title: "本应用需要使用定位权限",
          message: "需要您打开GPS,然后就可以顺利找到加油站啦!",
          buttonNeutral: "让我再想想",
          buttonNegative: "不行",
          buttonPositive: "打开GPS"
        }
      );
    if (granted === PermissionsAndroid.RESULTS.GRANTED) {
        await init({
          android: "****"
        });
        setNeedAddress(true);
    
        await Geolocation.getCurrentPosition(({ coords }) => {
          //console.log(coords);
          AsyncStorage.setItem("LAT", `${coords.latitude}`);
          AsyncStorage.setItem("LNG", `${coords.longitude}`);
        }, error => console.error(error));
      }
}

render() {
    return (
        <SafeAreaView></SafeAreaView>
    )
}

}

const mapStateToProps = (state) => ({

})

const mapDispatchToProps = {

}

export default connect(mapStateToProps, mapDispatchToProps)(DeviceAdd)
`

我是0.61.2, 同样也是没有反应,也不报错
`
import React, { Component } from 'react'
import { connect } from 'react-redux'
import { SafeAreaView } from 'react-native'
import { PermissionsAndroid } from "react-native";
import { init, Geolocation, setNeedAddress } from "react-native-amap-geolocation";

export class DeviceAdd extends Component {
constructor(props){
super(props);
}

componentDidMount() {
    this._getLocation();
}

async _getLocation() {
    let granted = await PermissionsAndroid.request(
        PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION,
    
        {
          title: "本应用需要使用定位权限",
          message: "需要您打开GPS,然后就可以顺利找到加油站啦!",
          buttonNeutral: "让我再想想",
          buttonNegative: "不行",
          buttonPositive: "打开GPS"
        }
      );
    if (granted === PermissionsAndroid.RESULTS.GRANTED) {
        await init({
          android: "****"
        });
        setNeedAddress(true);
    
        await Geolocation.getCurrentPosition(({ coords }) => {
          //console.log(coords);
          AsyncStorage.setItem("LAT", `${coords.latitude}`);
          AsyncStorage.setItem("LNG", `${coords.longitude}`);
        }, error => console.error(error));
      }
}

render() {
    return (
        <SafeAreaView></SafeAreaView>
    )
}

}

const mapStateToProps = (state) => ({

})

const mapDispatchToProps = {

}

export default connect(mapStateToProps, mapDispatchToProps)(DeviceAdd)
`

我的已经解决了 是我自己的问题 你可以参考下作者的index.js写的例子 另外我还有个原因是申请的高德key填的调试版的安全码填错了 我之前用的是全局的一个debug证书 后来发现项目安卓根目录下有个debug证书 修改了就可以获取到坐标了 仅供参考。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android Only for android bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants