如何解决react-native-geocoding 中的地理编码问题
Error Image 我正在尝试从 react native 中的纬度和经度值中获取地址(反向地理编码)。但得到上述错误。
fetch('https://maps.googleapis.com/maps/api/geocode/json?address=' + 41.89 + ',' + 12.49 + '&key=' + myApiKey)
.then((response) => response.json())
.then((responseJson) => {
console.log('ADDRESS GEOCODE is BACK!! => ' + JSON.stringify(responseJson));
})
.catch(error => console.log(error));
和
Geocoder.from(41.89,12.49)
.catch(error => console.log(error))
.then(json => {
console.log("json",json);
var addressComponent = json.results[0].address_components[0];
console.log("addressComponent",addressComponent);
});
属于 react-native-geocoding 报错
解决方法
您如何在代码中使用这些代码片段?
我尝试检查我的终端并且它工作正常。
以下是用于提取的 sample code 和代码片段:
import React,{ Component } from 'react';
import { Text,View,StyleSheet,Dimensions } from 'react-native';
import MapView from 'react-native-maps';
const styles = StyleSheet.create({
container: {
flex: 1,backgroundColor: '#fff',alignItems: 'center',justifyContent: 'center',},map: {
width: Dimensions.get('window').width,height: Dimensions.get('window').height,});
class MapApp extends Component {
componentDidMount = () => {
fetch(
'https://maps.googleapis.com/maps/api/geocode/json?address=' +
41.89 +
',' +
12.49 +
'&key=' +
'YOUR_KEY'
)
.then((response) => response.json())
.then((responseJson) => {
console.log(
'ADDRESS GEOCODE is BACK!! => ' + JSON.stringify(responseJson)
);
})
.catch((error) => console.log(error));
};
render() {
return (
<View style={styles.container}>
<MapView
style={styles.map}
initialRegion={{
latitude: 37.78825,longitude: -122.4324,latitudeDelta: 0.0922,longitudeDelta: 0.0421,}}>
</MapView>
</View>
);
}
}
export default MapApp;
这里是 react-native-geocoding 的 sample code 和代码片段:
import React,}}>
</MapView>
</View>
);
}
}
export default MapApp;
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。