如何使用Swift 3自定义Google地图信息窗口

4

Xcode版本: 8.1

目标:

用自定义信息窗口替换原生信息窗口

问题:

  1. 当我点击标记时,我的自定义信息窗口没有显示出来,但是原生的信息窗口显示了。
  2. 或者
  3. 如果我不删除myView.delegate = self(请参见我的代码和研究#21),则会显示Thread 1:signal SIGABRT。

我所做的:

  1. Created a .swift file and a .xib file with my custom infoWindow design.
  2. Inserted mapView function into 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

需要翻译的内容为一系列与 Google Maps iOS SDK 相关的链接。
1个回答

4
您是否实现了GMSMapViewDelegate?
ViewController: GMSMapViewDelegate {

   ...

}

看起来你之所以会出现错误(崩溃),是因为你将代理设置为了self,但是你的控制器并没有遵循该协议。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接