didTap事件
import UIKit
import GoogleMaps
import GooglePlaces
import CoreLocation
class ViewController: UIViewController{
@IBOutlet weak var mapViewSecond: UIView!
@IBOutlet weak var mapView: GMSMapView!
var zoomLevel: Float = 10.0
var mapViewV: GMSMapView!
var marker = GMSMarker()
override func viewDidLoad() {
super.viewDidLoad()
let camera = GMSCameraPosition.camera(withLatitude: 21.512740, longitude: 70.572224, zoom: 15.0)
mapView.mapType = GMSMapViewType.hybrid
mapView.camera = camera
mapView.delegate = self
showMarker(position: camera.target)
}
override func viewDidAppear(_ animated: Bool) {
}
func showMarker(position: CLLocationCoordinate2D){
marker.position = position
marker.title = "Palo Alto"
marker.snippet = "San Francisco"
marker.map = mapView
}
}
extension ViewController : GMSMapViewDelegate{
func mapView(_ mapView: GMSMapView, didTapInfoWindowOf marker: GMSMarker) {
print("didTapInfoWindowOf")
}
/* handles Info Window long press */
func mapView(_ mapView: GMSMapView, didLongPressInfoWindowOf marker: GMSMarker) {
print("didLongPressInfoWindowOf")
}
/* set a custom Info Window */
func mapView(_ mapView: GMSMapView, markerInfoWindow marker: GMSMarker) -> UIView? {
let view = UIView(frame: CGRect.init(x: 0, y: 0, width: 200, height: 70))
view.backgroundColor = UIColor.white
view.layer.cornerRadius = 6
let lbl1 = UILabel(frame: CGRect.init(x: 8, y: 8, width: view.frame.size.width - 16, height: 15))
lbl1.text = "Hi there!"
view.addSubview(lbl1)
let lbl2 = UILabel(frame: CGRect.init(x: lbl1.frame.origin.x, y: lbl1.frame.origin.y + lbl1.frame.size.height + 3, width: view.frame.size.width - 16, height: 15))
lbl2.text = "I am a custom info window."
lbl2.font = UIFont.systemFont(ofSize: 14, weight: .light)
view.addSubview(lbl2)
return view
}
func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D){
marker.position = coordinate
}
}
答案 0 :(得分:0)
您没有实现didTapMarker。
func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {
print("Marker tapped")
return true
}