【发布时间】:2017-10-15 06:03:30
【问题描述】:
我的代码运行正常,但是每当调用此函数时,我都会在移动设备上收到与此问题标题相同名称的错误。
_matchAddresses(id) {
fetch('https://myapp.com/rest/jobs/address/' + id)
.then((response) => response.json())
.then((responseJson) => {
var addresses = [];
console.log('addresses: ' + responseJson);
for (var i=0; i<responseJson.length; i++) {
addresses.push(responseJson[i]);
for (var j=0; j<addresses.length; j++) {
fetch('https://maps.googleapis.com/maps/api/geocode/json?address='+ addresses[j].split(" ") + '&key=googleapikey')
.then((response) => response.json())
.then((responseJson) => {
let lat = responseJson.results["0"].geometry.location.lat; //error here
let lng = responseJson.results["0"].geometry.location.lng; //error here
console.log("coordinates: " + lat + " " + lng); //returns coordinates every time
if (this._latMatch(userLat, lat) && this._lngMatch(userLng, lng)) {
this._myFunction();
console.log("fire");
}
})
.catch((error) => {
console.error(error);
});
}
}
});
}
我知道 lat 和 lng 已经定义了一些日志记录,所以我不明白为什么我仍然会收到错误。提前谢谢你。
【问题讨论】:
标签: json react-native fetch