0

有没有办法使用 phonegap 获取我在 iphone 上的当前位置并将该位置的标记覆盖到平面图上?我可以使用以下方法获取纬度和经度:

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

我不知道如何将其转换为标记并将其覆盖到图像上。有任何想法吗?

4

1 回答 1

0

using compass api + geolocation api. e.g.

<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');
}

I used this pattern.

于 2013-10-31T02:11:37.940 回答