ste*_*eed 5 xcode google-maps ios google-maps-sdk-ios swift
我正在尝试创建一个包含GMSMapView的UITableViewCell,其中GMSMaper在当前Position的中心。
问题是标记始终显示在当前位置的左上角,我不知道如何解决该问题。
我尝试按照以下步骤操作:使用UItableviewCell实现Google Map
这是我来自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
Run Code Online (Sandbox Code Playgroud)
这是我遇到的问题的屏幕截图: 标记位于地图的左上角
我有一个非常相似的问题。我通过更改我在视图生命周期中配置地图的时刻来解决它。
就我而言,我使用的是子视图控制器。我在 viewWillAppear
调用之前配置了地图,这导致地图无法正确居中(标记位于左上角)。我动了我的呼吁后,将viewWillAppear
它固定它。一个好地方是viewDidAppear
。
如果您正在使用单元格,您可能需要使用视图生命周期而不是控制器生命周期进行调查。
这没有写在 Google 文档的任何地方。