ios - 如何使用 Swift 3 自定义 googlemap infoWindow

标签 ios google-maps swift3 infowindow

Xcode 版本: 8.1

目标:

用自定义的替换原生的infoWindow

问题:

  1. 当我点击标记时,我的自定义 infoWindow 没有显示,而是原生的, 或者
  2. 线程 1:如果我不删除 myView.delegate = self,就会显示 SIGABRT 信号(参见我的代码和研究 #21)

我做了什么:

  1. 使用我的自定义信息窗口设计创建了一个 .swift 文件和一个 .xib 文件。
  2. 将 mapView 函数插入到 ViewController.swift 中:

    override func viewDidLoad() {
        super.viewDidLoad()
    

    ...

        let camera = GMSCameraPosition.camera(withLatitude: latitude,
                                              longitude: Longitude, zoom: 16)
        let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
        mapView.delegate = self  // Thread 1:signal SIGABRT shown if i add this line
        mapView.isMyLocationEnabled = true
        self.view = mapView
    
        let marker = GMSMarker()
        marker.position = CLLocationCoordinate2DMake(latitude, Longitude)
        marker.title = "Me"
        marker.map = mapView
        mapView.selectedMarker = marker
    }
    
    func mapView(_ mapView: GMSMapView, markerInfoWindow marker: GMSMarker) -> UIView? {
        let infoWindow = Bundle.main.loadNibNamed("CustomInfoWindow", owner: self.view, options: nil)!.first! as! CustomInfoWindow
        infoWindow.title.text = marker.title
        return infoWindow
    }
    

我的研究:

  1. https://developers.google.com/maps/documentation/ios-sdk/marker
  2. https://developers.google.com/maps/documentation/ios-sdk/reference/protocol_g_m_s_map_view_delegate-p
  3. https://forums.developer.apple.com/thread/8462
  4. http://kevinxh.github.io/swift/custom-and-interactive-googlemaps-ios-sdk-infowindow.html
  5. https://productforums.google.com/forum/#!topic/maps/w0sP7r3XAF4
  6. Custom InfoWindow for marker Google Maps SDK, Swift 2.0
  7. https://www.youtube.com/watch?v=ILiBXYscsyY
  8. Custom annotation view in Google Maps SDK
  9. Creating custom info window in swift with the Google maps iOS sdk?
  10. How to show a Info window in iOS Google maps without tapping on Marker?
  11. Custom info window in IOS google maps sdk
  12. IOS Google Map Custom InfoWindow Xib error
  13. Google Maps Info window's resizing based on the internal content
  14. Custom Info Window for Google Maps
  15. Custom InfoWindows issue -Google Maps iOS SDK-
  16. How to customize the InfoWindow of google map iOS SDK?
  17. swift 3 google maps custom infowindow
  18. How to initialise a UIView Class with a xib file in Swift, iOS
  19. https://github.com/ziyang0621/GoogleMaps-Swift/blob/master/GoogleMapSwift/ViewController.swift
  20. https://github.com/ryanmaxwell/GoogleMapsCalloutView
  21. Implementing custom markerInfoWindow in swift not working
  22. https://codedump.io/share/hh7CO7c2j3PI/1/custom-infowindow-for-marker-google-maps-sdk-swift-20

最佳答案

您是否实现了 GMSMapViewDelegate?

ViewController: GMSMapViewDelegate {

   ...

}

您似乎遇到了错误(崩溃),因为您将委托(delegate)设置为 self ,但您的 Controller 不符合该协议(protocol)。

关于ios - 如何使用 Swift 3 自定义 googlemap infoWindow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40634421/

相关文章:

core-data - 在 Swift 3 中删除核心数据实体中的所有数据

ios - DispatchGroup.wait() 卡住程序

ios - 制作类似于新的谷歌地图 iOS 应用程序的向上滑动 View ,多个 UIPanGestureRecognizer 的麻烦

iphone - 在 iOS 中更新/修改地址簿联系人后的通知

ios - 如何发送坐标进行解析并将其保存为解析PFGeopoint

ios - Cocoapods pod 创建目标,并在使用时更改 Xcode 中的目标

javascript - 谷歌地图 API 调整大小不起作用

android - 无法使用谷歌地图获取 map

ios - CocoaPods 和 Swift 3.0

ios - 使用 WantsFullScreenLayout 应用程序处理扩展高度状态栏的最佳实践?