ios - 点击 GMSPolygon Swift

标签 ios swift google-maps tap

我的 map 中有一些 GMSPolygon:

 let españa = GMSMutablePath()
    españa.add(CLLocationCoordinate2D(latitude: 42.11, longitude: -9.37))
    españa.add(CLLocationCoordinate2D(latitude: 43.94, longitude: -9.55))
    españa.add(CLLocationCoordinate2D(latitude: 43.60, longitude: -1.89))
    españa.add(CLLocationCoordinate2D(latitude: 42.02, longitude: 3.72))
    españa.add(CLLocationCoordinate2D(latitude: 36.16, longitude: -2.65))
    españa.add(CLLocationCoordinate2D(latitude: 37.10, longitude: -7.28))
    españa.add(CLLocationCoordinate2D(latitude: 42.08, longitude: -6.61))
<小时/>
    let polygonEspaña = GMSPolygon(path: españa)
    polygonEspaña.fillColor = UIColor(red : 0, green: 0, blue: 0, alpha: 0.05);
    polygonEspaña.strokeColor = .black
    polygonEspaña.strokeWidth = 2
    polygonEspaña.map = myMapView
    polygonEspaña.isTappable = true

我想点击它们来实现一些功能。

我实现了这个方法:

import UIKit
import GoogleMaps



class ViewController: UIViewController, CLLocationManagerDelegate, GMSMapViewDelegate {
}

当我点击它们时,什么也没有发生。

// ###### Click Country


private func myMapView(_ myMapView: GMSMapView, didTap overlay: GMSOverlay) {
    print("User Tapped Layer: \(overlay)")
}

我认为我的 GMSMapViewDelegate 存在问题,但我无法修复它,我该怎么做?

编辑:我也已经有了这个。

// ##### MAPA


    let mapCenter = GMSCameraPosition.camera(withLatitude: 48.23,
                                             longitude: 16.35,
                                             zoom: 3)

    myMapView.camera = mapCenter
    myMapView.setMinZoom(1, maxZoom: 8)

    myMapView.delegate = self


    // #### Estilo de mapa


    do {
        if let styleURL = Bundle.main.url(forResource: "style", withExtension: "json") {
            myMapView.mapStyle = try GMSMapStyle(contentsOfFileURL: styleURL)
        } else {
            NSLog("Unable to finde style.json")
        }
    } catch {
        NSLog("One or more of the map styles failed to load. \(error)")
    }

谢谢

最佳答案

首先,感谢您使用我的回答 this问题:)

为什么将委托(delegate)方法设为私有(private)?我认为这可能是它没有被调用的原因。删除它。

关于ios - 点击 GMSPolygon Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44314927/

相关文章:

ios - 如何在 iOS 中使用 Contacts Framework 获取更改的联系人

ios - imageView 无法连接到 Objective-C 中 IBOulet 的头文件

ios - 如何按数据大小缩小 IOS 中的 UIImage

ios - 在编辑模式下重新排序数据后如何保存更改

ios - 发布版本中的 Liker 错误 - 函数签名专门化 <Arg[2] = Exploded>

ios - 在 UIPageViewController 中跟踪页面索引的可靠方法 - Swift

ios - 按特定字符拆分字符串,iOS

javascript - Google Maps Remote .js 和 Access-Control-Allow-Origin

android - 在谷歌地图 v2 中显示多个标记

javascript - 单击时将类添加到标记