I try to make a (hybrid)webapp with Phonegap(3.7.0) and AngularJS that uses geolocation. My problem is that geolocation works in a browser, but not when I build the project in Phonegap and try to run it on a mobile device. When I remove the AngularJS controller in my Javascript the geolocator works like a charm on mobile devices. I tried to bootstrap AngularJS manually (for the DOM loading order), but that did not worked for me. Also the config file is correct at least I think.
Can anyone help me on this or giving me clues?
Thanks in advance
HTML
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale = 1.0">
<!-- Phonegap Javascript -->
<script src="js/cordova/cordova.js" type="text/javascript"></script>
<!-- AngularJS Javascript -->
<script src="js/angular/angular.js" type="text/javascript"></script>
<script src="js/angular/angular-route.js" type="text/javascript"></script>
<!-- Foundation for apps Javascript -->
<script src="js/vendor/modernizr.js"></script>
</head>
<body>
<div class="content-container" ng-app="mamyloeApp">
<div ng-controller="UitjesDichtbijController" class="list-view-uitje">
<ul ng-repeat="uitjes in uitjes.uitjes" class="list-item-uitje">
<li><a href='#'>
<div class="list-item-uitje-left">
<div class='uitje_list_image'>
<img src="../library/photos/{{uitjes.list_image}}" alt='image'>
</div>
</div>
<div class="list-item-uitje-right">
<div class="naam-uitje">{{uitjes.overview}}</div>
<div class="uitje-info">
<div class="plaats-uitje">{{uitjes.city}}({{uitjes.distance | number:1}}km)</div>
<div class="categorie-uitje">{{uitjes.category}}</div>
</div>
<div class="naam-local">{{uitjes.firstname}}</div>
</div>
</a></li>
</ul>
</div>
<script src="js/vendor/jquery.js"></script>
<script src="js/foundation.min.js"></script>
<script src="js/foundation/foundation.offcanvas.js"></script>
<!-- Controller scripts -->
<script src="js/load_list.js" type="text/javascript"></script>
</body>
Geolocator/AngularJS
var latitude = 0;
var longitude = 0;
var geo_initiate = false;
var App = angular.module('mamyloeApp', []);
App.controller('UitjesDichtbijController', function ($scope, $http) {
function geolocation()
{
var options = {enableHighAccuracy: true, timeout: 20000, maximumAge: 18000000};
watchID = navigator.geolocation.getCurrentPosition(onSuccess, onError, options);
function onSuccess(position)
{
latitude = position.coords.latitude;
longitude = position.coords.longitude;
console.log("GPS is ready");
console.log(latitude);
console.log(longitude);
$http.get("http://../Mamyloe_app/api/uitjes/" + latitude + "&" + longitude + "")
.success(function (response) {
$scope.uitjes = response;
console.log(response);
});
geo_initiate = true;
if(geo_initiate === true){
document.getElementById("content-container").style.visibility = "visible";
}
}
function onError(error)
{
if (error.code = 1)
{
alert("Enable your GPS!");
}
console.log("GPS is NOT ready");
}
}
$(document).ready(function () {
geolocation();
});
});
问题解决了,访问源是配置文件中的问题(访问源=“ *”),并且地图结构中有一些大写字母,phonegap不喜欢这样。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.