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

Geocode在开发环境获取位置成功,但是在release的时候报错 #244

Open
wqb2017 opened this issue Mar 16, 2020 · 0 comments
Open

Comments

@wqb2017
Copy link

wqb2017 commented Mar 16, 2020

import React from "react";
import { View, Text, PermissionsAndroid } from "react-native";
import styles from "./style";
import { MapView, Location, Geocode } from 'react-native-baidumap-sdk'

var idx = 1

export default class BaiduMapCom extends React.Component {
constructor(props) {
super(props)
this.state = {
curLocation: {
latitude: 39,
longitude: 113
},
markeTitle: '当前位置'
}
}
async componentDidMount (){
const granted = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION)
await Location.init()
Location.setOptions({ gps: true, distanceFilter: 3 })

// 用户允许获取当前地理位置
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
  Location.addLocationListener(curLocation => {
    this.setState({
      curLocation: curLocation
    }, () => {
      Geocode.reverse({
        latitude: curLocation.latitude,
        longitude: curLocation.longitude
      }).then(res => {
        console.log('Geocode', ++idx, res.description);
        this.setState({
          markeTitle: res.description
        })
      }).catch(err => {
        this.setState({
          markeTitle: '失败了'
        })
        // 失败
      })
    })
  })
  Location.start()
} else {
  // 失败了
}

}
render () {
const {
curLocation,
markeTitle
} = this.state
return(

<MapView
style={{ flex: 1 }}
center={curLocation}
zoomLevel={18}
>
<MapView.Marker
selected
ref="markerRef"
key={Math.random()}
title={markeTitle}
coordinate={curLocation}
>
</MapView.Marker>


{JSON.stringify(curLocation)}
{markeTitle}


)
}
}
`

@wqb2017 wqb2017 changed the title Geocode这个在开发环境可以拿到位置,但是在release的时候报错 Geocode在开发环境获取位置成功,但是在release的时候报错 Mar 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant