我是一个完全的 JS 新手,并尝试构建我的简单 JS 代码。目标是获取用户位置。
它可以工作,但是 getUserCoordinates 函数没有返回值?我认为这只是初学者的逻辑失败?
var app = {
geocoder: null,
init: function() {
this.geocoder = new google.maps.Geocoder();
coordinates = this.getUserCoordinates();
console.log(coordinates); // empty??
return;
},
getUserCoordinates: function() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(
function (coords) {
console.log(coords); // works Geocoder Object!
return coords; // the problem
}, // more code