onSuccess函數無限期運行,因爲會不斷詢問GPS接收器的座標。它包含一個函數createMap,只能執行一次。這是如何實現的?在函數外部做一個函數也不行,因爲它是作爲函數變量的參數值傳遞的。只運行一次禁止循環功能
watchID = navigator.geolocation.watchPosition(function(position) {onSuccess(position, arrMyLatLng);}, onError, options);
function onSuccess(position, arrMyLatLng)
{
var latitude , longitude ;
latitude = position.coords.latitude ;
longitude = position.coords.longitude;
var myLatLng = new google.maps.LatLng(latitude, longitude);
createMap(myLatLng, arrMyLatLng);// This feature will run for an indefinite number of times. It is only necessary once.
map.panTo(myLatLng) ;
}
到底是'createMap'什麼? – 2013-04-09 20:10:19