地理定位无法与Android中的PhoneGap Build一起使用
我添加了config.xml:
<feature name="http://api.phonegap.com/1.0/device" />
<feature name="http://api.phonegap.com/1.0/geolocation"/>
和
<preference name="permissions" value="INTERNET" />
完整的config.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<widget xmlns = "http://www.w3.org/ns/widgets"
xmlns:gap = "http://phonegap.com/ns/1.0"
id = "org.test.geo"
versionCode="10"
version = "1.0">
<name>Geo Test.</name>
<description>Geo Test.</description>
<author email="prueba@prueba.com">
Geo
</author>
<!-- PREFERENCE -->
<preference name="orientation" value="portrait" />
<preference name="fullscreen" value="true" />
<preference name="permissions" value="INTERNET" />
<!-- PLATFORM -->
<gap:platform name="android" />
<!-- FEATURE -->
<feature name="http://api.phonegap.com/1.0/device" />
<feature name="http://api.phonegap.com/1.0/geolocation"/>
</widget>
我使用了来自http://docs.phonegap.com/en/edge/cordova_geolocation_geolocation.md.html
的示例代码在index.html中
<!DOCTYPE html>
<html>
<head>
<title>Device Properties Example</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for device API libraries to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// device APIs are available
//
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: ' + position.timestamp + '<br />';
}
// onError Callback receives a PositionError object
//
function onError(error) {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
</script>
</head>
<body>
<p id="geolocation">Finding geolocation...</p>
</body>
</html>
我尝试使用虚拟设备和物理设备。我只能得到&#34;寻找地理位置......&#34;
没有错误。但问题似乎出现在navigator.geolocation.getCurrentPosition(onSuccess,onError);
谢谢!