简体   繁体   English

Ionic 5 Angular:iOs 模拟器中的 Google Maps InfoWindow 填充问题

[英]Ionic 5 Angular: Google Maps InfoWindow Padding Issue in iOs Simulator

I'm running into an issue with how a google maps InfoWindow is being rendered in my iOs simulator with Ionic5 Angular.我在使用 Ionic5 Angular 的 iOs 模拟器中如何渲染谷歌地图 InfoWindow 时遇到了问题。

Here's an image:这是一张图片:

在此处输入图像描述

As you can see, the padding is inconsistent, especially on the far right where the text is against the boundaries of the InfoWindow.如您所见,填充是不一致的,尤其是在文本与信息窗口边界相抵的最右侧。 It may be a timing issue, because if I delay the creation of the InfoWindow (with a setTimeout()) by a couple of seconds it usually renders correctly.这可能是一个时间问题,因为如果我将 InfoWindow(使用 setTimeout())的创建延迟几秒钟,它通常会正确呈现。

This doesn't happen in Android when I emulate the same project, as the padding is correct on that platform.当我模拟同一个项目时,Android 不会发生这种情况,因为该平台上的填充是正确的。 I've tried to manually add styling to the InfoWindow content, but there shouldn't be any reason I need to selectively add padding to iOs as opposed to Android.我尝试手动为 InfoWindow 内容添加样式,但没有任何理由我需要有选择地将填充添加到 iOs 而不是 Android。 I also shouldn't have to add an arbitrary timeout.我也不应该添加任意超时。

If anyone has any ideas it would be appreciated.如果有人有任何想法,将不胜感激。 I've boiled the code down as much as possible.我已经尽可能地简化了代码。

Simulator is iPhone 11 (13.2.2).模拟器是 iPhone 11 (13.2.2)。

Here's my Ionic info:这是我的离子信息:

Ionic:

   Ionic CLI                     : 5.4.2
   Ionic Framework               : @ionic/angular 5.1.1
   @angular-devkit/build-angular : 0.803.23
   @angular-devkit/schematics    : 8.1.3
   @angular/cli                  : 8.1.3
   @ionic/angular-toolkit        : 2.2.0

Cordova:

   Cordova CLI       : 9.0.0 (cordova-lib@9.0.1)
   Cordova Platforms : android 8.1.0, ios 5.1.1
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 4.1.3, (and 28 other plugins)

Utility:

   cordova-res : 0.6.0 (update available: 0.15.1)
   native-run  : 0.2.8 (update available: 1.0.0)

System:

   Android SDK Tools : 26.1.1 (/Users/me/Library/Android/sdk)
   ios-sim           : 8.0.2
   NodeJS            : v10.9.0 (/Users/me/.nvm/versions/node/v10.9.0/bin/node)
   npm               : 6.10.3
   OS                : macOS Catalina
   Xcode             : Xcode 11.5 Build version 11E608c

Here's the.ts file:这是.ts文件:

import { AfterViewInit, Component, ElementRef, ViewChild } from '@angular/core';

@Component({
  selector: 'app-dynamic-map',
  templateUrl: './dynamic-map.component.html',
  styleUrls: ['./dynamic-map.component.scss']
})
export class DynamicMapComponent implements AfterViewInit {
  @ViewChild('googleMap', { static: false }) private googleMap: ElementRef;

  private map: google.maps.Map;
  private marker: google.maps.Marker;
  private lat: number = 37.066076;
  private lng: number = -119.897168;

  constructor() {}

  ngAfterViewInit() {
    const mapProp: any = {
      center: new google.maps.LatLng(this.lat, this.lng),
      zoom: 13
    };

    this.map = new google.maps.Map(this.googleMap.nativeElement, mapProp);
    google.maps.event.addListenerOnce(this.map, 'tilesloaded', () => {
      this.addMarkerWithInfoWindow();
    });
  }

  addMarkerWithInfoWindow() {
    const infoWindow = new google.maps.InfoWindow({
      content: '<b>Address</b>: 1234 W Main Street'
    });

    this.marker = new google.maps.Marker({
      position: new google.maps.LatLng(this.lat, this.lng),
      map: this.map
    });
    infoWindow.open(this.map, this.marker);
  }
}

And the.html和.html

<div #googleMap style="width:100%; height: 100%" class="googleMap"></div>

@jwBurnside You can add style for your contentString which is in InfoWindow. @jwBurnside 您可以为 InfoWindow 中的 contentString 添加样式。

Your InfoWindow您的信息窗口

const infoWindow = new google.maps.InfoWindow({
      content: '<div id="content"><b>Address</b>: 1234 W Main Street</div>'
 });

and your css to be和你的 css 是

#content {
  padding: 5px;
}

It'll be fix your right alignment in InfoWindow popup.它将在 InfoWindow 弹出窗口中修复您正确的 alignment。

Reference: https://developers.google.com/maps/documentation/javascript/examples/infowindow-simple参考: https://developers.google.com/maps/documentation/javascript/examples/infowindow-simple

Maps library is adding overflow: scroll to the container when creating InfoWindow pop up.地图库添加溢出:创建InfoWindow弹出时overflow: scroll到容器。 While this works for other browsers, it does not seem to behave the same for mobile browser for iPhone.虽然这适用于其他浏览器,但对于 iPhone 的移动浏览器,它的行为似乎并不相同。

在此处输入图像描述

Add following style to fix the issue:添加以下样式以解决问题:

.gm-style .gm-style-iw-d {
  -webkit-overflow-scrolling: auto;
}

Just came up with another solution.刚刚想出了另一个解决方案。 The right and bottom spacing comes from overflow: scroll added inline to .gm-style.gm-style-iw-d .右侧和底部间距来自overflow: scroll添加到.gm-style.gm-style-iw-d So the idea is to remove that spacing since behavior is not consistent.所以这个想法是删除那个间距,因为行为不一致。 Then add your own spacing using your custom styles as needed.然后根据需要使用自定义 styles 添加自己的间距。 In this case your custom spacing will be consistent on Android and iOS.在这种情况下,您的自定义间距将在 Android 和 iOS 上保持一致。

To remove spacing:要删除间距:

.gm-style .gm-style-iw-d {
  overflow: auto !important;
}

PS Thanks to those two answers for info: PS感谢这两个答案的信息:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM