【问题标题】:iOS - Best way to display google map in UITableViewCelliOS - 在 UITableViewCell 中显示谷歌地图的最佳方式
【发布时间】:2016-03-02 13:42:11
【问题描述】:
我有我的自定义表格视图单元格,上面有谷歌地图 (GMSMapView)。该单元格位于表格视图的底部。
我显示地图的第一种方法是将 GMSMapView 添加为单元格的子视图。我的第二种方法是制作地图快照并将其添加到单元格上。但在这两种情况下,我的表格视图滚动都很不稳定。原因是地图加载。但是现在不推荐使用 startRendering 方法,所以我无法预取它。
是否有机会避免 tableView 抽搐?
【问题讨论】:
标签:
ios
swift
google-maps
uitableview
gmsmapview
【解决方案1】:
如果您的表格视图位置位于底部,请尝试将其用作表格视图的页脚视图。
我试过这样:
func getMapView() {
GMSServices.provideAPIKey("YOUR_API_KEY")
let camera = GMSCameraPosition.camera(withLatitude: pLatitude!, longitude: pLongitude!, zoom: 10.0)
let mapView = GMSMapView.map(withFrame: CGRect.init(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 250), camera: camera)
// Using map as footerview
propertyDetailsTable.tableFooterView = mapView
// Creates a marker in the center of the map.
let marker = GMSMarker()
marker.position = CLLocationCoordinate2D(latitude: pLatitude!, longitude: pLongitude!)
marker.title = pTitle
marker.snippet = pCityname
marker.icon = #imageLiteral(resourceName: "marker_2")
marker.map = mapView
mapView.selectedMarker = marker
}