我在使用Geocoder在本地反应中获取地址时收到此错误:
对象{“代码”:4,“消息”:“地理编码时来自服务器的错误。接收的数据位于错误的'origin'字段中。检查它是否有更多信息。”,“origin”:对象{“结果”:数组[],“状态”:“ZERO_RESULTS”,},}
我正在使用“react-native-geocoding”依赖
我的代码包含在这里:
Geocoder.init(GOOGLE_API_KEY); //google api key
Geocoder.from(latitude,longitude)
.then(json => {
var addressComponent = json.results[0].address_components;
console.log(JSON.stringify(addressComponent));
})
.catch(error => console.warn(error));
需要一些帮助?
你需要改变他的方式
getData(){
Geocoder.init("xxxxxxxxxxxxxxxxxxxxxxxxxx");
Geocoder.from(41.89, 12.49)
.then(json => {
var addressComponent = json.results[0].formatted_address;
// console.log(addressComponent);
console.log(addressComponent)
alert(addressComponent);
})
.catch(error => console.warn(error));