如何在React本机中解决“地理编码时来自服务器的错误...”?

问题描述 投票:1回答:1

我在使用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));

需要一些帮助?

react-native google-api google-geocoder
1个回答
0
投票

你需要改变他的方式

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));
© www.soinside.com 2019 - 2024. All rights reserved.