<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport"
content="width=device-width, initial-scale=1.0" />
<title>Sample</title>
<script src="cordova-2.7.0.js" type="text/javascript"></script>
<script type="text/javascript">
if (!navigator.userAgent.toLowerCase().match('chrome')) {
document.write("<script src='phonegap.js'><\/script>");
}
</script>
</head>
<body onload="onLoaded()">
<div class="info" style="font-size:12px">CCN TEST</div>
<script>
function onLoaded() {
alert('onLoaded');
document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady() {
alert('onDeviceReady');
if(window.navigator.geolocation)
{
alert('你的應用程式支援地理位置定位!');
var geolocation=window.navigator.geolocation;
geolocation.getCurrentPosition(getPositionSuccess, getPositionError);
}else
{
alert('你的程式不支援地理位置定位!');
}
}
function getPositionSuccess(position){
alert('getPositionSuccess');
var lat=position.coords.latitude;
var lon=position.coords.longitude;
alert('你所在的位置:經度'+lat+',緯度'+lon);
}
function getPositionError(err){
alert('getPositionError');
alert('code:'+err.code+'\n'+
'message:'+err.message+'\n');
}
</script>
</body>
</html>
- Jun 09 Mon 2014 12:10
[PhoneGap] 獲得目前地理位置
全站熱搜
留言列表