build.phonegap.com版本的android应用程序
我创建了一个Adroid应用程序,我想在其中检查手机的位置。我启动了emulator安装应用程序,每次我想检查它是否失败。是仿真器出了问题(因为它不是真正的手机)还是我做得不对build.phonegap.com版本的android应用程序,android,cordova,Android,Cordova,我创建了一个Adroid应用程序,我想在其中检查手机的位置。我启动了emulator安装应用程序,每次我想检查它是否失败。是仿真器出了问题(因为它不是真正的手机)还是我做得不对 <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta name="fo
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
<title>Hello World</title>
<script type="text/javascript" src="cordova-2.1.0.js"></script>
<script text="text/javascript">
function startUp(){
document.getElementById("H1").innerHTML = "Checking your location...";
document.addEventListener("deviceready", onDeviceReady, false)
}
function onDeviceReady() {
navigator.geolocation.getCurrentPosition(onSuccess, onError);
}
// onSuccess Geolocation
//
function onSuccess(position) {
var element = document.getElementById('location');
element.innerHTML = 'Latitude: ' + position.coords.latitude + '<br />' +
'Longitude: ' + position.coords.longitude + '<br />' +
'Altitude: ' + position.coords.altitude + '<br />';
document.getElementById("H1").innerHTML = "";
}
// onError Callback receives a PositionError object
//
function onError(error) {
document.getElementById("H1").innerHTML = "Fail to check your location.";
}
</script>
</head>
<body style="margin:0px;" onload="startUp()" bgcolor="#000">
<div class="app" style="background-color:#4D4D4D">
<font color="#FF9900" size="2"><h1 id="H1" style="font-family:courier new;"></h1></font>
<p id="location"></p>
</div>
</body>
</html>
你好,世界
函数启动(){
document.getElementById(“H1”).innerHTML=“检查您的位置…”;
文件。添加的监听器(“deviceready”,onDeviceReady,false)
}
函数ondevicerady(){
navigator.geolocation.getCurrentPosition(onSuccess,onError);
}
//成功地理定位
//
成功时的功能(位置){
var元素=document.getElementById('location');
element.innerHTML='Latitude:'+position.coords.Latitude+'
'+
'经度:'+position.coords.Longitude+'
'+
'高度:'+position.coords.altime+'
';
document.getElementById(“H1”).innerHTML=“”;
}
//OneError回调接收PositionError对象
//
函数onError(错误){
document.getElementById(“H1”).innerHTML=“无法检查您的位置。”;
}
HTML5文件和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 = "com.park.manager"
versionCode="10"
version = "0.1.9">
<name>ParkingManager</name>
<description>
A system, which manages parking side areas.
</description>
<author href="" email="">
Parking Side Manager Team
</author>
<preference name="phonegap-version" value="2.1.0" />
<preference name="orientation" value="landscape" />
<preference name="target-device" value="universal" />
<preference name="fullscreen" value="true" />
<preference name="android-installLocation" value="auto" />
<icon src="icon.png" />
<gap:splash src="splash.png" />
<feature name="http://api.phonegap.com/1.0/geolocation"/>
<feature name="http://api.phonegap.com/1.0/network"/>
</widget>
停车场经理
管理停车场侧区域的系统。
停车场管理小组
确保在清单XML中添加粗略和精细位置的权限
phone gap有它的优点,但它不会解决一些主要问题,比如必须手工完成清单。如果您在知道如何添加这些权限之前使用java制作了应用程序。如果不使用,请检查如何执行
除此之外,您的cordova geolaction调用是正确的,我以前从他们的示例中使用过它。上次我使用PhoneGap时,清单在清单文件中已经具有正确的权限 您很可能需要为模拟器提供模拟数据。
这是仿真器,你需要一部真正的手机,因为仿真器是一件痛苦的事情,你知道如何才能正常工作。你的Javascript和html都很好