如何在 React Native 中解决“地理编码时服务器出错......”?

Rez*_*aul 5 google-api google-geocoder react-native

在 react native 中使用 Geocoder 获取地址时出现此错误:

Object { "code": 4, "message": "地理编码时服务器出错。接收到的数据位于错误的'origin'字段中。检查它以获取更多信息。", "origin": Object { "results":数组 [], "status": "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));
Run Code Online (Sandbox Code Playgroud)

需要一些帮助?

Eve*_*ver 0

我通过更改 google API 密钥解决了这个问题。