我有一個基本的Android應用程序,鏈接到幾個外部網頁。我已經在這些網頁上放置了phonegap.js,並試圖獲取GPS信息,但沒有得到任何東西。基本上,該應用程序設置爲使用web視圖來加載外部頁面。外部網頁只有手機網站的示例代碼,但我沒有收到任何GPS信息。如果js和html頁面都在外部服務器上,我怎麼才能到phonegap API?從外部頁面呼叫phonegap API
<!DOCTYPE html>
<html>
<head>
<title>Device Properties Example</title>
<script type="text/javascript" charset="utf-8" src="phonegap-1.1.0.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for PhoneGap to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// PhoneGap is ready
//
function onDeviceReady() {
navigator.geolocation.getCurrentPosition(onSuccess, onError);
}
// onSuccess Geolocation
//
function onSuccess(position) {
var element = document.getElementById('geolocation');
element.innerHTML = 'Latitude: ' + position.coords.latitude + '<br />' +
'Longitude: ' + position.coords.longitude + '<br />' +
'Altitude: ' + position.coords.altitude + '<br />' +
'Accuracy: ' + position.coords.accuracy + '<br />' +
'Altitude Accuracy: ' + position.coords.altitudeAccuracy + '<br />' +
'Heading: ' + position.coords.heading + '<br />' +
'Speed: ' + position.coords.speed + '<br />' +
'Timestamp: ' + new Date(position.timestamp) + '<br />';
}
// onError Callback receives a PositionError object
function onError(error) {
alert("error");
}
</script>
</head>
<body>
<p id="geolocation">Finding my geolocation...</p>
</body>
</html>
粘貼您的Home.java以及.. – ghostCoder