0

I have some GMSPolygon in my map:

 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

I want tap them to make some functions.

I implemented this method:

import UIKit
import GoogleMaps



class ViewController: UIViewController, CLLocationManagerDelegate, GMSMapViewDelegate {
}

When I tap them nothing happen.

// ###### Click Country


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

I think that i have a issue in my GMSMapViewDelegate but i can´t fix it, how could i do that?

EDIT: I Already have this also.

// ##### 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)")
    }

Thanks

eshirima
  • 3,837
  • 5
  • 37
  • 61

2 Answers2

0

First of, thank you for using my answer from this question :)

Why did you make the delegate method private? I think that might be the reason why its not getting called. Remove it.

eshirima
  • 3,837
  • 5
  • 37
  • 61
  • Sorry, but i don´t know about private method. How can remove it? Thank you! – Eloyu F.Bent Jun 02 '17 at 17:35
  • Just use your backspace to delete the word `private` from the function itself. So your function should be `func myMapView(_ myMapView: GMSMapView, didTap overlay: GMSOverlay)` instead of `private func myMapView(_ myMapView: GMSMapView, didTap overlay: GMSOverlay)` – eshirima Jun 02 '17 at 17:37
  • I did it and still no working. I have also location func and does not work. // ###### Click Country func myMapView(_ myMapView: GMSMapView, didTap overlay: GMSOverlay) { print("User Tapped Layer: \(overlay)") } // #### Find location in console. func location (_ myMapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D) { print("You tapped at \(coordinate.latitude), \(coordinate.longitude)") } – Eloyu F.Bent Jun 02 '17 at 17:48
  • I am not sure how the assignment operator works but can you try moving `polygonEspaña.isTappable = true` above `polygonEspaña.map = myMapView` – eshirima Jun 02 '17 at 17:55
  • Still no working. I did that and nothing happen. Thanks @Emil David – Eloyu F.Bent Jun 03 '17 at 08:19
  • I tested in other View and it works perfectly. I have a problem, because i have a RevealViewController. i think that something happen with it! somebody knows why it does not work with RevealViewController menu? – Eloyu F.Bent Jun 03 '17 at 08:43
0

Finally it works.

I had a problem with my slide menu:

RevealViewController

I don´t know why with the RevealViewController, functions from:

GSMapViewDelegate 

does not work

Now when i tap in my polygon i receive a text in the console.

But i have the full information about my Polygon, i need the name of it.

For example, if i click in Spain, i want to receive "Your are tapped in Spain".

Thanks