Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/100.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何使用谷歌地图API使我的GMSPolygon在Swift中可点击_Ios_Swift_Google Maps_Polygon_Gmsmapview - Fatal编程技术网

Ios 如何使用谷歌地图API使我的GMSPolygon在Swift中可点击

Ios 如何使用谷歌地图API使我的GMSPolygon在Swift中可点击,ios,swift,google-maps,polygon,gmsmapview,Ios,Swift,Google Maps,Polygon,Gmsmapview,GoogleMapsAPI工作正常,所有二进制库都链接,包括target的“其他链接器标志”中的-Obj,并构造了objc头文件,这段代码基本上是直接从Google开发者演示中获取的,用于添加事件点击。然而,出于某种原因——即使我的地图、多边形和标记都可以工作——我也无法弄清楚如何使我的单个多边形可点击。(我最终想让它从红色变为绿色,并在用户点击时返回)。我是swift和xcode的初学者,使用最新的更新,真的需要一些帮助 这是我的密码: class ViewController: UIView

GoogleMapsAPI工作正常,所有二进制库都链接,包括target的“其他链接器标志”中的-Obj,并构造了objc头文件,这段代码基本上是直接从Google开发者演示中获取的,用于添加事件点击。然而,出于某种原因——即使我的地图、多边形和标记都可以工作——我也无法弄清楚如何使我的单个多边形可点击。(我最终想让它从红色变为绿色,并在用户点击时返回)。我是swift和xcode的初学者,使用最新的更新,真的需要一些帮助

这是我的密码:

class ViewController: UIViewController, GMSMapViewDelegate {

override func loadView() {
    let camera = GMSCameraPosition.camera(withLatitude: 40.0, longitude: -75.3, zoom: 17.0)
    let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
    mapView.delegate = self
    self.view = mapView

    // Creates a marker in the center of the map.
    let marker = GMSMarker()
    marker.position = CLLocationCoordinate2D(latitude: 40.0, longitude: -75.3)
    marker.title = "University1"
    marker.isTappable = true
    marker.map = mapView

    // Create a rectangular path
    let K1 = GMSMutablePath()
    K1.add(CLLocationCoordinate2D(latitude: 40.04080470744396, longitude: -75.34219389549136))
    K1.add(CLLocationCoordinate2D(latitude: 40.04082335573317, longitude: -75.34220634745961))
    K1.add(CLLocationCoordinate2D(latitude: 40.0407983689258, longitude: -75.34226262271473))
    K1.add(CLLocationCoordinate2D(latitude: 40.04078009018794, longitude: -75.34224985832812))
    let K1polygon = GMSPolygon(path: K1)
    K1polygon.fillColor = UIColor(red: 0.25, green: 0, blue: 0, alpha: 0.05);
    K1polygon.strokeColor = .red
    K1polygon.strokeWidth = 2
    K1polygon.isTappable = true
    K1polygon.map = mapView

}}
func mapView(_ mapView: GMSMapView, didTap overlay: GMSOverlay) {
print("You did it!")
}

let geocoder = GMSGeocoder()

func mapView(_ mapView: GMSMapView, willMove gesture: Bool) {
mapView.clear()
}

func mapView(_ mapView: GMSMapView, idleAt cameraPosition: GMSCameraPosition)    {
geocoder.reverseGeocodeCoordinate(cameraPosition.target) { (response, error)    in
    guard error == nil else {
        return
    }

    if let result = response?.firstResult() {
        let marker = GMSMarker()
        marker.position = cameraPosition.target
        marker.title = result.lines?[0]
        marker.snippet = result.lines?[1]
        marker.map = mapView
    }
}}