javascript - 从 google api 函数返回 lat 和 lng
问题描述
一段时间以来,我一直试图让 lat 和 lng 脱离这个函数,但我真的不知道为什么我不能返回它。它 console.logs 它在函数中就好了。
有人可以帮我提供一个解决方案来返回 lat 和 lng 吗?
<script>
function latLngFind(postcode){
var location = postcode + ' United Kingdom'
axios.get('https://maps.googleapis.com/maps/api/geocode/json',{
params:{
address:location,
key:'my key'
}
})
.then(function(responce){
lat = (responce.data.results[0].geometry.location.lat);
lng = (responce.data.results[0].geometry.location.lng);
console.log([lat,lng]);
return[lat,lng];
})
.catch(function(error){
console.log(error);
});
}
postcode = 'S404UH'
console.log(latLngFind(postcode));
</script>
解决方案
推荐阅读
- kubernetes - 如何安全地将 kubeconfig 提供给 kubectl
- python - 有没有办法使用 Python Requests 库确认 POST 请求是否实际上是通过代理发送的?
- python - 如何在 Tkinter 的动态大小按钮中填充图像
- mysql - SQLTrackerStore 不创建表
- json - Azure Policy 添加多个标记名称和标记值
- node.js - MongoDB客户端(nodejs)不关闭连接
- python-3.x - 芹菜错误 - 工人:热关机(主进程)
- dialogflow-es - 对 Google 推送通知的操作删除权限
- sql - 并行数据仓库中是否有等效于“TRY_CAST”的功能?
- spring - 同步执行状态动作