我花了很多时间试图解决这个问题。 我的应用程序上有一张 map ,该 map 会在加载后加载实际位置。
出于某种原因,在我的查看器(使用 Ionic Viewer)上它可以在我的本地设备和本地主机上运行,但是当我直接从 Xcode 在我的 iPhone 上测试它时, map 不会加载。
如果我编译一个 .apk 并在 android 上测试它, map 也不会加载。
.controller('mapaCtrl', function($scope, $compile, $location) {
$scope.goPayment = function() {
$location.path('side-menu/history');
};
var myLatlng = new google.maps.LatLng(34.603711, -58.381585);
var mapOptions = {
center: myLatlng,
zoom: 16,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map"), mapOptions);
navigator.geolocation.getCurrentPosition(function(pos) {
map.setCenter(new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude));
var myLocation = new google.maps.Marker({
position: new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude),
map: map,
title: "My Location"
});
google.maps.event.addListener(myLocation, 'click', function() {
infowindow.open(map,myLocation);
});
});
var contentString = "<div><a ng-click='clickTest()'>Pagar Aqui!</a></div>";
var compiled = $compile(contentString)($scope);
var infowindow = new google.maps.InfoWindow({
content: compiled[0]
});
$scope.map = map;
$scope.clickTest = function() {
$location.path('side-menu/pay');
};
})
有什么线索吗?
最佳答案
可能有多种因素会影响您应用的正常功能,请考虑以下因素:
- 可能存在对谷歌地图的请求被阻止的问题。查看白名单插件:https://stackoverflow.com/a/29896923/1956540
尝试添加 geoLocation 权限,这是我发现的一篇文章,可以引导您完成整个过程:http://www.gajotres.net/using-cordova-geoloacation-api-with-google-maps-in-ionic-framework/
It is also important to wrap geolocation code into Ionic deviceready event, execution will timeout without it:
ionic.Platform.ready(函数() { //代码在这里
我不确定是否有必要再拥有这些,但我知道对于 Android,您可以验证 AndroidManifest.xml 中是否存在所需的权限:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
您可能可以搜索一些 iOS 等效项,但我认为安装该插件应该可以自行完成。
--
关于android - map 在设备上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37196388/