【发布时间】:2017-06-01 18:46:29
【问题描述】:
我的地图中有一些 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
-
是的,我有。还有一个 MapStyle 工作正常。谢谢
-
我的回答有帮助吗?
标签: ios swift google-maps tap