我有一些GMSPolygon在我的地图:点击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)")
}
感谢
你有这条线吗? :myMapView.delegate = self – Beninho85
是的,我拥有它。还有一个MapStyle可以工作。谢谢 –
我的回答有帮助吗? – eshirima