Phonegap构建地理位置不起作用
Posted
技术标签:
【中文标题】Phonegap构建地理位置不起作用【英文标题】:Phonegap build Geolocation not working 【发布时间】:2015-10-27 07:06:28 【问题描述】:js:我使用简单的警报来显示位置,并使用 phonegap build 进行编译。显示设备就绪警报!但没有任何其他警报!
document.addEventListener("deviceready", getDeviceLocation , false);
function getDeviceLocation ()
alert('device ready');
navigator.geolocation.getCurrentPosition(showPosition, showError, enableHighAccuracy: true );
function showPosition(position)
alert('show postion called');
alert("Latitude: " + position.coords.latitude +
"Longitude: " + position.coords.longitude);
function showError(error)
alert('show error called');
alert("Errorcode: " + error.code +
"Errormessage: "+ error.message );
html:html页面如下:
<!DOCTYPE html>
<html ng-app>
<head>
<link rel="stylesheet" href="style.css">
<!--<link rel="stylesheet" href="bootstrap.css">-->
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="bootstrap.css">
<!-- Latest compiled and minified javascript -->
<script src="angular.min.js"></script>
<script src="cordova.js"></script>
<script src="angular.animate.min.js"></script>
<script src="angular.route.min.js"></script>
<link rel="stylesheet" href="font-awesome.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>
<body>
</body>
<script type="text/javascript" src="pro.js"></script>
<script type="text/javascript" src="bootstrap.js"></script>
<script type="text/javascript" src="script.js"></script>
</html>
【问题讨论】:
【参考方案1】:此代码对我有用。希望能帮到你。
newMapForGuest: function()
// setting here default latitude and longitude in case geolocation does not work.
var defaultLatLng = new google.maps.LatLng(1.290, 103.851);
if ( navigator.geolocation )
function success(pos) // function will call on success
alert('Latitude: '+ pos.coords.latitude +' Longitude: '+pos.coords.longitude);
function fail(error) // function will call on fail
alert('error message: ' +error);
// intializing geolocation to get current position
navigator.geolocation.getCurrentPosition(success, fail, maximumAge: 500000, enableHighAccuracy:true, timeout: 10000);
else
// in case geolocation does not work then call code mentioned here.
,
【讨论】:
以上是关于Phonegap构建地理位置不起作用的主要内容,如果未能解决你的问题,请参考以下文章