【发布时间】:2016-02-02 06:20:35
【问题描述】:
我已经在我的 ionic/cordova 应用程序中实现了 cordova-plugin-geolocation 插件。当我在浏览器和 iOS 设备上运行该应用程序时,它可以完美运行。但是,当我尝试在 Android 设备上运行它时,地图不会显示,也不会获得您当前的 GPS 坐标。超时后会抛出以下错误:
[对象位置错误]
首先我添加了插件(以及cordova-plugin-whitelist插件通过运行这是cli:
cordova plugin add cordova-plugin-geolocation
cordova plugin add cordova-plugin-whitelist
然后我将以下内容添加到我的 index.html:
<script src="//maps.googleapis.com/maps/api/js"></script>
<script src="lib/angular-google-maps/dist/angular-google-maps.min.js"></script>
然后我修改了我的 app.js 以包含“uiGmapgoogle-maps”:
var app = angular.module('myApp', ['ionic', 'ngCordova', 'uiGmapgoogle-maps']);
我的地图 HTML:
<!-- Google map -->
<ui-gmap-google-map center='map.center' zoom='map.zoom'>
<ui-gmap-marker coords="marker.coords" options="marker.options" events="marker.events" idkey="marker.id" closeClick="hideMarkerPopup()" onClicked="showMarkerPopup()"></ui-gmap-marker>
</ui-gmap-google-map>
最后是我的控制器中的逻辑:
ionic.Platform.ready(function() {
var posOptions = {
enableHighAccuracy: true,
timeout: 20000,
maximumAge: 0
};
// Display 'loading' dialog
$ionicLoading.show({
template: 'Loading...'
});
$cordovaGeolocation.getCurrentPosition(posOptions).then(function(position) {
// Apply new values to map
$scope.location = {};
$scope.location.lat = position.coords.latitude;
$scope.location.long = position.coords.longitude;
$scope.map = {
center: {
latitude: $scope.location.lat,
longitude: $scope.location.long
},
zoom: 16,
pan: 1
};
$scope.marker = {
id: 0,
coords: {
latitude: $scope.location.lat,
longitude: $scope.location.long
}
};
$scope.marker.options = {
draggable: false
};
// Dismiss 'loading' dialog
$ionicLoading.hide();
}, function(err) {
// Dismiss 'please wait' dialog
$ionicLoading.hide();
var alertPopup = $ionicPopup.alert({
title: 'GPS Error',
template: err
});
});
}); // ionic.Platform.ready END
但是,正如我所说。它适用于浏览器和 iOS 设备,但不适用于 Android 设备。有帮助吗?
【问题讨论】:
标签: angularjs cordova ionic-framework cordova-plugins