2012-11-06 41 views
1

我試圖創建基於位置()方法對小葉JS地圖類單張JS:做活動對象需要定義事件處理

這裏成功的事件處理程序之前被實例化是我在瞬間:

function initMap() { 
    var map = L.map('map').locate({setView: false}); 

    map.on('locationfound', function(s) { 
     map.setView(s.latlng).setZoom(14); 
    }); 

    map.on('locationerror', function(e) { 
     message: 'Sorry, We were unable to determine your current location.'; 
    }); 

    L.tileLayer('http://{s}.tile.cloudmade.com/0e35616818144f159fa412e57f190939/997/256/{z}/{x}/{y}.png', { 
     attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://cloudmade.com">CloudMade</a>', 
     maxZoom: 18 
    }).addTo(map); 
} 

是「s」或「E」需要定義事件處理程序之前被啓動,或者確實S和E假設通過事件處理程序的作用LocationEvent對象。如果是這樣,那麼執行此操作的正確方法是什麼?

回答

0

它不需要啓動。您作爲事件偵聽器傳遞的函數會被自動調用某些對象作爲參數(本例中爲位置數據)。