iOS中使用nativescript-google-maps-sdk的地图中心错误

mne*_*neu 2 nativescript angular2-nativescript nativescript-telerik-ui nativescript-angular nativescript-plugin

在iOS中,当我放置marker和mapView位置时,地图不会居中显示,但是如果我将手机移至横向并再次旋转至纵向,则地图中心将显示正常。在Adnroid工作正常。

您可以在以下github问题中获得更多信息:https : //github.com/dapriett/nativescript-google-maps-sdk/issues/322

sai*_*web 5

我亲自面对过这个问题,发现它基本上是iOS上的布局问题。iOS对提供给MapView的XML元素的heightwidth属性值有所不同。正如问题本身所描述的那样,解决问题的方法是resizing运行时映射(因为旋转屏幕使其经过调整大小例程)。在地图渲染的开头应用这种荒谬的逻辑即可解决该问题。

这是我的方法:

width以XML 提供MapView 的值:

<maps:mapView width="100%" mapReady="onMapReady" />
Run Code Online (Sandbox Code Playgroud)

并设置heightmap内部onMapReady方法的,延迟为100毫秒。

/* if you want to set height in DIP */

setTimeout(() => this.mapView.height = 500, 100);
Run Code Online (Sandbox Code Playgroud)

或者如果您想以百分比设置高度

/* [0.85 means 85% here] */

setTimeout(() => this.mapView.height = {
    unit: '%',
    value: 0.85
}, 100);
Run Code Online (Sandbox Code Playgroud)

100毫秒的延迟使其resize生效。在iOS 12.1上测试