We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
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} ) } } `
The text was updated successfully, but these errors were encountered:
No branches or pull requests
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 })
}
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}
)
}
}
`
The text was updated successfully, but these errors were encountered: