Cordova地理定位在Android上不起作用
我想在Android上使用地理定位。我用Apache Cordova编写应用程序。 地理定位在andoid pc模拟器和andoid手机上都不起作用 我试着 及 My Platform/android/AndroidManifest.xml:Cordova地理定位在Android上不起作用,android,cordova,geolocation,cordova-3,Android,Cordova,Geolocation,Cordova 3,我想在Android上使用地理定位。我用Apache Cordova编写应用程序。 地理定位在andoid pc模拟器和andoid手机上都不起作用 我试着 及 My Platform/android/AndroidManifest.xml: <?xml version='1.0' encoding='utf-8'?> <manifest android:hardwareAccelerated="true" android:versionCode="1" android:ver
<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="0.0.1" android:windowSoftInputMode="adjustPan" package="net.example.test" xmlns:android="http://schemas.android.com/apk/res/android">
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="19" />
<application android:debuggable="true" android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/app_name" android:name="Test" android:theme="@android:style/Theme.Black.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
我在互联网上(也在stackoverflow上)发现了很多问题,但都不起作用:-(
你知道我哪里出错了吗
更新: 现在我在index.html中有了:
<!DOCTYPE html>
<html><head>
<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() {
console.log('in onDeviceReady()');
navigator.geolocation.getCurrentPosition(onSuccess, onError);
}
// onSuccess Geolocation
function onSuccess(position) {
console.log('in onSuccess()');
console.log(position.coords.latitude);
console.log(position.coords.longitude);
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) {
console.log('in onError()');
console.log(error.code);
console.log(error.message);
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
</script>
</head><body><p id="geolocation">Finding geolocation...</p></body></html>
你能帮帮我吗?好吧,我为这个问题挣扎了几个小时(也许几天),找到了以下链接; 我不确定它是否已经或将被弃用。 但无论如何,我的解决方案是“rmorg.apache.cordova.geolocation”,因为它根本不起作用 然后我看到了mozilla的以下链接: 为了得到用户的位置,我所做的唯一一件事是:
<!DOCTYPE html>
<html>
<head>
<title>Device Properties Example</title>
</head>
<body>
<script src="http://192.168.43.15:8081/target/target-script-min.js#anonymous"></script>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
function geo_success(position) {
alert("success" + " : " + position.coords.latitude + ", position.coords.longitude");
//do_something(position.coords.latitude, position.coords.longitude);
}
function geo_error() {
alert("Sorry, no position available.");
}
var geo_options = {
enableHighAccuracy: true,
maximumAge : 30000,
timeout : 27000
};
var wpid = navigator.geolocation.getPosition(geo_success, geo_error, geo_options);
</script>
<p id="geolocation">Finding geolocationsss...</p>
</body>
</html>
设备属性示例
功能geo_成功(职位){
警报(“成功”+:“+position.coords.latitude+”,position.coords.longitude”);
//做某事(position.coords.lation,position.coords.longitude);
}
函数geo_error(){
警告(“对不起,没有职位可用。”);
}
变量geo_选项={
EnableHighAccurance:正确,
最高限额:30000,
超时:27000
};
var wpid=navigator.geolocation.getPosition(地理位置成功、地理位置错误、地理位置选项);
查找地理位置
注意:它在phonegapDevApp wirelessy上确实有效,但在真正的设备上不起作用。这就是为什么我一直在寻找并痛苦地了解到js文件应该在正文而不是标题中,并将我的navigator.geolocation.getPosition命令从“initialize”改为“initialize”。然后再次添加了geolocation插件
是的,最后,我的应用程序运行得很好。它在我的应用程序启动时显示了我当前位置的地图
希望它也能对你起作用!好吧,我花了几个小时(可能是几天)来解决这个问题,并找到了以下链接; 我不确定它是否已经或将被弃用。 但无论如何,我的解决方案是“rmorg.apache.cordova.geolocation”,因为它根本不起作用 然后我看到了mozilla的以下链接: 为了得到用户的位置,我所做的唯一一件事是:
<!DOCTYPE html>
<html>
<head>
<title>Device Properties Example</title>
</head>
<body>
<script src="http://192.168.43.15:8081/target/target-script-min.js#anonymous"></script>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
function geo_success(position) {
alert("success" + " : " + position.coords.latitude + ", position.coords.longitude");
//do_something(position.coords.latitude, position.coords.longitude);
}
function geo_error() {
alert("Sorry, no position available.");
}
var geo_options = {
enableHighAccuracy: true,
maximumAge : 30000,
timeout : 27000
};
var wpid = navigator.geolocation.getPosition(geo_success, geo_error, geo_options);
</script>
<p id="geolocation">Finding geolocationsss...</p>
</body>
</html>
设备属性示例
功能geo_成功(职位){
警报(“成功”+:“+position.coords.latitude+”,position.coords.longitude”);
//做某事(position.coords.lation,position.coords.longitude);
}
函数geo_error(){
警告(“对不起,没有职位可用。”);
}
变量geo_选项={
EnableHighAccurance:正确,
最高限额:30000,
超时:27000
};
var wpid=navigator.geolocation.getPosition(地理位置成功、地理位置错误、地理位置选项);
查找地理位置
注意:它在phonegapDevApp wirelessy上确实有效,但在真正的设备上不起作用。这就是为什么我一直在寻找并痛苦地了解到js文件应该在正文而不是标题中,并将我的navigator.geolocation.getPosition命令从“initialize”改为“initialize”。然后再次添加了geolocation插件
是的,最后,我的应用程序运行得很好。它在我的应用程序启动时显示了我当前位置的地图
希望它也能为你工作!我以前在android上遇到过cordova插件geolocation最新版本的问题。 试试下面的版本
<plugin name="cordova-plugin-geolocation" spec="2.4.3" />
我之前在android上遇到过cordova插件geolocation最新版本的问题。 试试下面的版本
<plugin name="cordova-plugin-geolocation" spec="2.4.3" />
如果您正在使用cordova 3.3,为什么要查看cordova 2.4的文档?而且您没有说明您有什么问题(控制台中有错误?只是没有找到位置?)我发送了错误链接。我尝试了3.3.0版本的代码(代码与2.4相同)。我看不到任何错误或调试消息。我的应用程序编写了“查找位置…”我在我的应用程序中添加了“console.log('Test log');”,但在“adb logcat”输出中我看不到它。你找到这个问题的解决方案了吗?我也遇到了同样的问题。如果你使用cordova 3.3,为什么要看cordova 2.4的文档?而且你也没有说你有什么问题(控制台出错?只是没有得到位置?)我发送了错误链接。我尝试了3.3.0版本的代码(代码与2.4版本相同)。我没有看到错误或调试消息。我的应用程序在屏幕上写“查找位置…”,然后什么也没有发生。我在我的应用程序中添加了“console.log('Test log');”,但在“adb logcat”上输出我看不到它。你找到这个问题的任何解决方案了吗。我也遇到了同样的问题。设置geo\u选项。超时为我做了这件事。感谢分享设置geo\u选项。超时为我做了这件事。感谢分享
<plugin name="cordova-plugin-geolocation" spec="2.4.3" />