我遇到了一个非常奇怪的问题,大约一周前开始出现。
我有一个使用Google地图的ionic v1应用程序(不是Cordova插件,而是Google地图的Web版),这些地图在模态框中打开并且一直能够正常工作(至少有两年时间)。
我当前拥有的JS代码如下:
$scope.pickup_map = {
center: item.location,
zoom: 14,
control: pickupMapControl,
mapOptions: {
draggable: true,
disableDefaultUI: true,
zoomControl: true,
zoomControlOptions: {
style: google.maps.ZoomControlStyle.LARGE,
position: google.maps.ControlPosition.RIGHT_CENTER
}
}
}
然后在openModal方法中:
$timeout(
() => {
const map = pickupMapControl.getGMap()
map.setCenter(new google.maps.LatLng(item.location.latitude, item.location.longitude))
google.maps.event.trigger(map, 'resize')
},
100
)
我在HTML中有以下代码:
<script src="https://maps.googleapis.com/maps/api/js?libraries=geometry&libraries=places&key=AIzaSyAUKvpku-JhbniZY80NLq_A2Ejgk_b_lUc&v=3.31" async></script>
and<ion-modal-view>
<ion-header-bar class="bar-calm">
<h1 class="title">Pick-up Location</h1>
<div class="button button-clear" ng-click="closeMapViewer()"><span class="icon ion-close"></span></div>
</ion-header-bar>
<ion-content class="pickup-location-viewer">
<ui-gmap-google-map
center="pickup_map.center"
zoom="pickup_map.zoom"
control="pickup_map.control"
options="pickup_map.mapOptions"
draggable="true"
data-tap-disabled="true"
ng-if="pickup_map.control"
>
<ui-gmap-circle center="marker.position" stroke="marker.stroke" fill="marker.fill" radius="marker.radius"></ui-gmap-circle>
<ui-gmap-marker coords="userPosition" icon="{ url: 'img/user-pos-icon.png' }" idKey="user"></ui-gmap-marker>
</ui-gmap-google-map>
</ion-content>
</ion-modal-view>
在桌面浏览器的Chrome和Safari中以及Android设备上,这个功能都可以正常工作。
我的iOS屏幕截图看起来像这样:
我特意添加了这张屏幕截图,因为我知道很多人会有Google标志等出现在底部的经历,但在这种情况下不会发生。
真正奇怪的是,如果我微调一下地图的缩放或移动,它就会显示出来,然而,之后通过编程设置缩放或重新定位地图则没有任何作用。
我已经检查了网络请求,可以看到在iOS中,在我移动地图之前不会初始发送到Google的API调用,而在Web和Android上,它们绝对会在打开模态时发送。所以问题似乎是由于某种原因在iOS中没有正确初始化,尽管如上所述,代码库中最近没有更改过任何内容。
我意识到当前Google Maps的最新稳定版本是v3.34,而我仍在使用v3.31,但我测试了每个增量版本直到v3.35,但都没有任何区别。
此外-虽然不是很重要-只有在iOS中缩放控件才会消失,也许这是一个相关的问题,尽管它们在地图实际开始显示后甚至都不会出现。
对于这个问题有什么建议吗?