Google maps api 3 为谷歌地图标记分配动作点击,swift 2
我有一个谷歌地图标记,我希望当我点击该标记时,将我发送到另一个viewController,或在我的地图上显示一个按钮Google maps api 3 为谷歌地图标记分配动作点击,swift 2,google-maps-api-3,swift2,ios9,xcode7,Google Maps Api 3,Swift2,Ios9,Xcode7,我有一个谷歌地图标记,我希望当我点击该标记时,将我发送到另一个viewController,或在我的地图上显示一个按钮 let marker1 = GMSMarker() marker1.position = CLLocationCoordinate2DMake(24.8236423, -107.4234671) marker1.appearAnimation = kGMSMarkerAnimationPop marker1.icon = UIImage(named: "flag_icon")
let marker1 = GMSMarker()
marker1.position = CLLocationCoordinate2DMake(24.8236423, -107.4234671)
marker1.appearAnimation = kGMSMarkerAnimationPop
marker1.icon = UIImage(named: "flag_icon")
marker1.title = "Any title"
marker1.snippet = "Any text"
marker1.map = mapView
我解决了,这是tap函数
//Market Tap Function
func mapView(mapView: GMSMapView!, didTapMarker marker: GMSMarker!) -> Bool {
let myFirstButton = UIButton()
myFirstButton.setTitle("✸", forState: .Normal)
myFirstButton.setTitleColor(UIColor.blueColor(), forState: .Normal)
myFirstButton.frame = CGRectMake(15, -50, 300, 500)
myFirstButton.addTarget(self, action: "pressed:", forControlEvents: .TouchUpInside)
self.view.addSubview(myFirstButton)
return true
}
您可以将这些步骤用于swift 4和5
func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {
//do what ever you want
return true
}
GMSMapViewDelegate
1
import UIKit
import GoogleMaps
import GooglePlaces
class HomeVC: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.mapView.delegate = self
}
}
2
extension HomeVC:GMSMapViewDelegate {
func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {
print("Do what ever you want.")
return true
}
}
如何调用此函数?@dipenbaks必须首先使类实现GMSMapViewDelegate,而不是assigm mapView.delegate=self。然后,每次按下标记时都会调用该函数,如下所示: