如何使用 Swift 自定义 googlemap infoWindow 3
How to customise googlemap infoWindow using Swift 3
Xcode版本:
8.1
目标:
用自定义的 infoWindow 替换原生的 infoWindow
问题:
- 当我点击标记时,我的自定义 infoWindow 没有显示,而是原生的,
或者
- 线程 1:signal 如果我不删除就会显示 SIGABRT
myView.delegate = self
(参见我的代码和研究 #21)
我做了什么:
- 使用我的自定义信息窗口设计创建了一个 .swift 文件和一个 .xib 文件。
已将 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
}
我的研究:
- https://developers.google.com/maps/documentation/ios-sdk/marker
- https://developers.google.com/maps/documentation/ios-sdk/reference/protocol_g_m_s_map_view_delegate-p
- https://forums.developer.apple.com/thread/8462
- http://kevinxh.github.io/swift/custom-and-interactive-googlemaps-ios-sdk-infowindow.html
- https://productforums.google.com/forum/#!topic/maps/w0sP7r3XAF4
- https://www.youtube.com/watch?v=ILiBXYscsyY
- Custom annotation view in Google Maps SDK
- Creating custom info window in swift with the Google maps iOS sdk?
- How to show a Info window in iOS Google maps without tapping on Marker?
- Custom info window in IOS google maps sdk
- Google Maps Info window's resizing based on the internal content
- Custom Info Window for Google Maps
- Custom InfoWindows issue -Google Maps iOS SDK-
- How to customize the InfoWindow of google map iOS SDK?
- swift 3 google maps custom infowindow
- How to initialise a UIView Class with a xib file in Swift, iOS
- https://github.com/ziyang0621/GoogleMaps-Swift/blob/master/GoogleMapSwift/ViewController.swift
- https://github.com/ryanmaxwell/GoogleMapsCalloutView
- Implementing custom markerInfoWindow in swift not working
- https://codedump.io/share/hh7CO7c2j3PI/1/custom-infowindow-for-marker-google-maps-sdk-swift-20
你实现了 GMSMapViewDelegate 了吗?
ViewController: GMSMapViewDelegate {
...
}
您似乎遇到了错误(崩溃),因为您将委托设置为自我,但您的控制器不符合该协议。
Xcode版本: 8.1
目标:
用自定义的 infoWindow 替换原生的 infoWindow
问题:
- 当我点击标记时,我的自定义 infoWindow 没有显示,而是原生的, 或者
- 线程 1:signal 如果我不删除就会显示 SIGABRT
myView.delegate = self
(参见我的代码和研究 #21)
我做了什么:
- 使用我的自定义信息窗口设计创建了一个 .swift 文件和一个 .xib 文件。
已将 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 }
我的研究:
- https://developers.google.com/maps/documentation/ios-sdk/marker
- https://developers.google.com/maps/documentation/ios-sdk/reference/protocol_g_m_s_map_view_delegate-p
- https://forums.developer.apple.com/thread/8462
- http://kevinxh.github.io/swift/custom-and-interactive-googlemaps-ios-sdk-infowindow.html
- https://productforums.google.com/forum/#!topic/maps/w0sP7r3XAF4
- https://www.youtube.com/watch?v=ILiBXYscsyY
- Custom annotation view in Google Maps SDK
- Creating custom info window in swift with the Google maps iOS sdk?
- How to show a Info window in iOS Google maps without tapping on Marker?
- Custom info window in IOS google maps sdk
- Google Maps Info window's resizing based on the internal content
- Custom Info Window for Google Maps
- Custom InfoWindows issue -Google Maps iOS SDK-
- How to customize the InfoWindow of google map iOS SDK?
- swift 3 google maps custom infowindow
- How to initialise a UIView Class with a xib file in Swift, iOS
- https://github.com/ziyang0621/GoogleMaps-Swift/blob/master/GoogleMapSwift/ViewController.swift
- https://github.com/ryanmaxwell/GoogleMapsCalloutView
- Implementing custom markerInfoWindow in swift not working
- https://codedump.io/share/hh7CO7c2j3PI/1/custom-infowindow-for-marker-google-maps-sdk-swift-20
你实现了 GMSMapViewDelegate 了吗?
ViewController: GMSMapViewDelegate {
...
}
您似乎遇到了错误(崩溃),因为您将委托设置为自我,但您的控制器不符合该协议。