2013-07-15 90 views
0

有沒有辦法使用phonegap在iphone上獲取當前位置,並將該位置的標記覆蓋到平面圖上?我可以用得到我的緯度和經度:如何使用phonegap疊加圖像上的當前位置?

alert('Latitude: '   + position.coords.latitude   + '\n' + 
'Longitude: '   + position.coords.longitude); 

我不知道如何將這種轉換爲一個標記,它覆蓋到的圖像。有任何想法嗎?

回答

0

using compass api + geolocation api。 例如

<script type="text/javascript" charset="utf-8"> 
var watchID = null; 
document.addEventListener("deviceready", onDeviceReady, false); 

function onDeviceReady() { 
    startWatch(); 
} 

function startWatch() { 
    var options = { frequency: 1000 }; 
    watchID = navigator.compass.watchHeading(onSuccess, onError, options); 
} 

/* 
function stopWatch() { 
    if (watchID) { 
     navigator.compass.clearWatch(watchID); 
     watchID = null; 
    } 
}*/ 

function onSuccess(heading) { 
    navigator.geolocation.getCurrentPosition(onSuccess2, onError2); 
} 

function onError(compassError) { 
    alert('Compass error: ' + compassError.code); 
} 

function onSuccess2(heading) { 
    alert('Latitude: '   + position.coords.latitude   + '\n' + 
'Longitude: '   + position.coords.longitude); } 

// onError: Failed to get the heading 
// 
function onError2(compassError) { 
    alert('code: ' + error.code + '\n' + 
      'message: ' + error.message + '\n'); 
} 

我使用了這種模式。

相關問題