视图左上角的GMSMarker图标(iOS) [英] GMSMarker icon in the top left corner of the view (iOS)

查看:133
本文介绍了视图左上角的GMSMarker图标(iOS)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个UITableViewCell,其中包含一个GMSMapView,该GMSMapView的GMSMarker位于当前Position的中心.

I am trying to create a UITableViewCell containing a GMSMapView with a GMSMarker at the center of the current Position.

问题在于标记始终显示在当前位置的左上角,我不知道如何解决该问题.

The problem is that the marker always appears at the top left corner of the current position and I don't know how to solve the problem.

我尝试执行以下步骤:使用UItableviewCell实施Google Map

I tried to follow these steps: Implementing a Google Map with UItableviewCell

这是我来自cellForRowAt的代码:

here is my code from cellForRowAt:

let locationCell = tableView.dequeueReusableCell(withIdentifier: "activityLocationCell") as! ActivityLocationCell

let latitude = CLLocationDegrees(activity.coordinates![0])
let longitude = CLLocationDegrees(activity.coordinates![1])
let position = CLLocationCoordinate2D(latitude: latitude, longitude: longitude)

locationCell.googleMapView.camera = GMSCameraPosition.camera(withTarget: position, zoom: 15)

let marker = GMSMarker(position: position)
marker.groundAnchor = CGPoint(x: 0.5, y: 0.5)
marker.map = locationCell.googleMapView

return locationCell

这是我的问题的屏幕截图: 标记位于地图的左上角

Here is a screenshot of my problem: marker is at the top left corner of the map

推荐答案

我遇到了一个非常相似的问题.我通过更改在视图生命周期中配置地图的时间来解决该问题.

I had a pretty similar issue. I resolved it by changing the moment I configure the map in the view lifecycle.

就我而言,我使用的是子视图控制器.我在之前 viewWillAppear之前配置了地图,这导致地图无法正确居中(标记位于左上角).我将通话移至viewWillAppear之后的之后,并对其进行了修复.一个好地方是viewDidAppear.

In my case, I was using a child view controller. I was configuring the map before viewWillAppear was called which caused the map to not center properly (the marker was on the top left corner). I moved my call to after the viewWillAppear and it fixed it. A good place would be viewDidAppear.

如果您正在使用单元,则可能需要调查视图生命周期而不是控制器生命周期.

If you are using a cell, you will probably need to investigate with the view lifecycle instead of the controller lifecycle.

这没有写在Google文档的任何地方.

This is not written anywhere on the Google documentation.

这篇关于视图左上角的GMSMarker图标(iOS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆