当我检测到用户的位置时,我试图调用一个函数,但我必须确保它使用 setTimeout() 函数的唯一方法。没有它我怎么能得到它?
_detectUserLocation: function(map, marker) {
self = this;
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var pos = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
map.setCenter(pos);
map.setZoom(12);
marker.setPosition(pos);
self._updateAddressPartsViaReverseGeocode(marker.getPosition());
setTimeout(function() {
self._loadByUserLocation(self.parsed);
}, 2000);
}, function(error) {
marker.setPosition(new google.maps.LatLng(-23.5489433, -46.6388182));
}, { timeout:5000 });
}
else {
marker.setPosition(new google.maps.LatLng(-23.5489433, -46.6388182));
}
},
现在,我必须使用 setTimeout() 函数来避免在系统获得用户位置之前 JS 调用 _loadByUserLocation() 。
我该如何解决?