ユーザーの位置を検出したときに関数を呼び出そうとしていますが、それを確実にする唯一の方法は 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));
}
},
今のところ、システムがユーザーの位置を取得する前に JS 呼び出し _loadByUserLocation() を避けるために、setTimeout() 関数を使用する必要があります。
どうすれば修正できますか?