我无法使用React Native从google map API中获取经纬度。
我正在使用此扩展程序来自动完成 react-native-google-places-autocomplete
我正在构建一个乘车共享应用程序,为此,我必须获取用户的接送地点。经过许多努力,我完成了自动完成工作。
现在的问题是,我需要所选位置的纬度和经度。我试过了但是我不能。
需要帮助,谢谢。
<GooglePlacesAutocomplete
placeholder='Enter Location'
minLength={2}
autoFocus={false}
returnKeyType={'default'}
fetchDetails={true}
onPress={(data, details = null) => {
// I tried this One
// Tried to get the reponce from API HERE
console.log(data, details);
}}
styles={{
textInputContainer: {
backgroundColor: 'rgba(0,0,0,0)',
borderTopWidth: 0,
borderBottomWidth:0
},
textInput: {
marginLeft: 0,
marginRight: 0,
height: 38,
color: '#5d5d5d',
fontSize: 16
},
predefinedPlacesDescription: {
color: '#1faadb'
},
}}
query={{
// available options: https://developers.google.com/places/web-service/autocomplete
key: 'YOUR API KEY',
language: 'en', // language of the results
types: '(cities)' // default: 'geocode'
}}
currentLocation={false}
/>
答案 0 :(得分:0)
尝试一下:
import RNGooglePlaces from 'react-native-google-places';
//constructor here
openSearchModal() {
RNGooglePlaces.openAutocompleteModal()
.then((place) => {
// place represents user's selection from the
// suggestions and it is a simplified Google Place object.
console.log(place); //here you will have lat and long
this.setState({
address: place,
})
})
.catch(error => console.log("ERROR: " + error.message)); // error is a Javascript Error object
}
render() {
<TouchableOpacity onPress={() => this.openSearchModal()}>
<Text>Map</Text>
</TouchableOpacity>
}