2013-01-11 10 views
0

我會努力解決如何拼湊下面的代碼來處理'Heading_change'而不是'Click'。有沒有人管理過這個?即使沒有鼠標點擊,它仍然是(事件)嗎?使用MVCArray上的'Heading_changed'

google.maps.event.addListener(map, 'click', addLatLng); 

/** 
* Handles click (or other) events on a map, and adds a new point to the Polyline. 
* @param {MouseEvent} mouseEvent 
*/ 
    function addLatLng(event) { 

     var path = flightPath.getPath(); 

    // Because path is an MVCArray, we can simply append a new coordinate 
    // and it will automatically appear 
     path.push(event.latLng); 

    // Add a new marker at the new plotted point on the polyline. 
     var marker = new google.maps.Marker({ 
     position: event.latLng, 
     title: '#' + path.getLength(), 
     map: map 
     });alert("Done"); 
    } 

回答

0

簡單地改變

google.maps.event.addListener(map, 'click', addLatLng); 

google.maps.event.addListener(map, 'heading_changed', addLatLng); 

然而,heading_changed事件沒有與它相關聯的MouseEvent,即你不能在一個事件對象獲得的經緯度通過事件發生的位置,因爲heading_changed事件沒有與之關聯的位置。所以你需要重新思考你想要的功能。

+0

謝謝你,我設法做到了。 –