2017-06-01 53 views
0

我有一些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)") 
    } 

感谢

+0

你有这条线吗? :myMapView.delegate = self – Beninho85

+0

是的,我拥有它。还有一个MapStyle可以工作。谢谢 –

+0

我的回答有帮助吗? – eshirima

回答

0

首先,感谢您对我的回答从this问题:)

你为什么要把委托方法private?我认为这可能是它未被召唤的原因。去掉它。

+0

对不起,但我不知道私人方法。 如何删除它?谢谢! –

+0

只需使用退格键从函数本身删除“private”一词。所以你的函数应该是'func myMapView(_ myMapView:GMSMapView,didTap overlay:GMSOverlay)'而不是'private func myMapView(_ myMapView:GMSMapView,didTap overlay:GMSOverlay)' – eshirima

+0

我做到了,仍然没有工作。 我也有位置功能,不起作用。 // ######点击国家 FUNC myMapView(_ myMapView:GMSMapView中,didTap覆盖:GMSOverlay){ 打印( “用户点击图层:\(覆盖)”) } //# ###在控制台中查找位置。 FUNC位置(_ myMapView:GMSMapView中,didTapAt坐标:CLLocationCoordinate2D){ 打印( “你在\(coordinate.latitude),\(coordinate.longitude)抽头”) } –

0

最后它的工作原理。

我与我的幻灯片菜单的一个问题:

RevealViewController 

我不知道为什么与RevealViewController,从功能:

GSMapViewDelegate 

不会当我工作

现在点击我的多边形我收到控制台中的文本。

但我有关于我的多边形的完整信息,我需要它的名称。

例如,如果我点击西班牙,我想收到“你在西班牙被挖掘”。

谢谢