我正在尝试使用Google地图地理编码服务。它将值作为lat和lng在数组中吐出。我删除了这些值并将它们放在一个单独的var中,以便我可以在我的代码中的其他位置使用它们。
function geoCode(place,num){
var location = place;
axios.get('https://maps.googleapis.com/maps/api/geocode/json',{
params:{
address:location,
key:''
}
})
.then(function(response){
hospitalLocations[num]={
lat:float(response.data.results[0].geometry.location.lat),
lng:float(response.data.results[0].geometry.location.lng),
};
})
.catch(function(error){
console.log(error);
});
在设置中,我记得var:
console.log(typeof hospitalLocations);
console.log(hospitalLocations);
console.log(hospitalLocations[0]);
typeof给了我“对象”。 hospitalLocations为我提供了一个完整的数组,我可以打开并查看与常规数组相同的值。 但是,当我检查一个特定的值时,它给了我undefined。 有没有办法取出内部的价值? 感谢
答案 0 :(得分:0)
你应该注意到android:largeHeap="true"
是一个对象而不是一个数组..我可以从中理解:
hospitalLocations
通常,如果你想迭代一个对象,你将使用以下方式:
...
.then(function(response){
hospitalLocations[num]={
lat:float(response.data.results[0].geometry.location.lat),
lng:float(response.data.results[0].geometry.location.lng),
};
})
...
如果您正在寻找的话,我希望这会对您有所帮助。