我正在使用Cordova地理定位插件的项目,该插件将搜索您周围的用户。但是,我无法从模拟器获取地理位置,也无法在设备上获取地理位置。在我使用之前获取坐标但非常不稳定。在修复错误的一些代码之后,我现在大部分时间都会收到错误。我试了一个星期但没有成功 任何意见或建议?
JavaScript文件:
/***********Geolocation GEOLOCATION*************/
// Wait for device API libraries to load
document.addEventListener("deviceready", onDeviceReady, false);
// device APIs are available
//
function onDeviceReady() {
var options = {maximumAge: 0, timeout: 15000, enableHighAccuracy:true};
navigator.geolocation.getCurrentPosition(onSuccess, onError, options);
}
// onSuccess Geolocation
//
var onSuccess = function(position) {
document.getElementById('userLat').value = position.coords.latitude;
document.getElementById('userLong').value = position.coords.longitude;
document.getElementById('extraUserLat').value = position.coords.latitude;
document.getElementById('extraUserLong').value = position.coords.longitude;
//document.getElementById('extraUserTest').innerHTML = position.coords.longitude;
};
// onError Callback receives a PositionError object
//
function onError(error) {
alert('There Was An Error Getting Your Location. Please Check That You Have WiFi and Location Services Enabled. ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
XML文件:
<js-module src="www/Coordinates.js" name="Coordinates">
<clobbers target="Coordinates" />
</js-module>
<js-module src="www/PositionError.js" name="PositionError">
<clobbers target="PositionError" />
</js-module>
<js-module src="www/Position.js" name="Position">
<clobbers target="Position" />
</js-module>
<js-module src="www/geolocation.js" name="geolocation">
<clobbers target="navigator.geolocation" />
</js-module>
<config-file target="config.xml" parent="/*">
<feature name="Geolocation">
<param name="ios-package" value="CDVLocation"/>
<feature name="http://api.phonegap.com/1.0/geolocation" />
</feature>
</config-file>
<header-file src="ios/CDVLocation.h" />
<source-file src="ios/CDVLocation.m" />
<framework src="CoreLocation.framework" />
<config-file target="*-Info.plist" parent="NSLocationWhenInUseUsageDescription">
<string></string>
</config-file>
HTML: