3

I get to know after searching that idleAtCameraPosition and didChangeCameraPosition this methods are called when the map moves . How can i write this method for swift? I have set delegate to CLLocationManagerDelegate and GMSMapViewDelegate but still this methods are not called. I have written method as below:

func mapView(mapView: GMSMapView!, didChangeCameraPosition position: GMSCameraPosition!) {
                print(position)
}

func mapView(mapView:GMSMapView!,idleAtCameraPosition position:GMSCameraPosition!)
{
    print(position)

}

But my method is not getting called. Also I want to customise info window just like done here : Custom Info Window for Google Maps . But can't find the methods how to do same in swift. I am new to swift s o not getting this.

Community
  • 1
  • 1
Pooja Shah
  • 977
  • 16
  • 45

2 Answers2

7

Maybe too late, but you must extend the class with GMSMapViewDelegate. For example:

class NearMeViewController: CLLocationManagerDelegate, GMSMapViewDelegate 

Then, how Ztan says, you have to delegate your map with:

self.mapView.delegate = self

With this, the method didChangeCameraPosition will respond every time that that camera's position is changed.

Hope it helps.

Guillaume Fache
  • 813
  • 10
  • 21
Hernan Duque
  • 73
  • 1
  • 5
4

You need to import the GMSMapViewDelegate at the top of your class

put self.mapView.delegate = self in your viewDidLoad()

and then you can use this method

func mapView(mapView: GMSMapView, idleAtCameraPosition position: GMSCameraPosition) {

        // You can use the position.target for get the current camera position

}
Tommy
  • 979
  • 8
  • 15