现在试图让地理定位工作太久了。
控制台给我以下错误:
Coordinates.js:69未捕获的ReferenceError:模块未定义(匿名函数)@ Coordinates.js:69
geolocation.js:24未捕获的ReferenceError:未定义require(匿名函数)@ geolocation.js:24
Position.js:22未捕获的ReferenceError:未定义require(匿名函数)@ Position.js:22
PositionError.js:38未捕获的ReferenceError:模块未定义(匿名函数)@ PositionError.js:38
whitelist.js:23找不到Content-Security-Policy元标记。使用cordova-plugin-whitelist插件时请添加一个。"
我的HTML主管:
<!doctype html> <html class=""> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Study Time</title> <link href="resources/css/boilerplate.css" rel="stylesheet" type="text/css"> <!--<link href="resources/css/index.css" rel="stylesheet" type="text/css">--> <link href="vendors/jquery/slidemenu.hamburger.css" rel="stylesheet" type="text/css"> <link href="resources/css/index.css" rel="stylesheet" type="text/css"> <link href="resources/css/switch.css" rel="stylesheet" type="text/css"> <script src="cordova.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <!-- <script src="vendors/phonegap/micVolume.js"></script> --> <script src="vendors/phonegap/location/Coordinates.js"></script> <script src="vendors/phonegap/location/geolocation.js"></script> <script src="vendors/phonegap/location/Position.js"></script> <script src="vendors/phonegap/location/PositionError.js"></script> <script src="resources/js/location.js"></script> </head>
我的location.js文件是:
// onSuccess Callback
// This method accepts a Position object, which contains the
// current GPS coordinates
//
function getLoc() {
GPSLocation.getCurrentPosition(onSuccess, onError);
}
var onSuccess = function(position) {
alert('Latitude: ' + position.coords.latitude + '\n' +
'Longitude: ' + position.coords.longitude + '\n' +
'Altitude: ' + position.coords.altitude + '\n' +
'Accuracy: ' + position.coords.accuracy + '\n' +
'Altitude Accuracy: ' + position.coords.altitudeAccuracy + '\n' +
'Heading: ' + position.coords.heading + '\n' +
'Speed: ' + position.coords.speed + '\n' +
'Timestamp: ' + position.timestamp + '\n');
};
// onError Callback receives a PositionError object
//
function onError(error) {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
我在src / android中有必需的java类,在config.xml中也有<gap:plugin name="org.apache.cordova.geolocation" />
。
答案 0 :(得分:0)
我不确定为什么这不起作用但从那时起我决定尝试远离phonegap网络界面并使用cordova命令行。这使我可以轻松安装插件,现在可以按预期工作了。