Tung Fam
Tung Fam

Reputation: 8167

Google maps sdk - doesn't move the view to new point

Seems to be a very simple task but for some reason it doesn't work.

I init the map and place the 1st location this way:

    self.view = self.mapView
    self.mapView?.isMyLocationEnabled = true

    let KBPLocation = CLLocationCoordinate2DMake(50.341707, 30.893606)
    let camera = GMSCameraPosition.camera(withLatitude: KBPLocation.latitude, longitude: KBPLocation.longitude, zoom: 12)
    self.mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)

then i have an func that does this:

func moveToNextLocation()   {
        self.mapView?.camera = GMSCameraPosition.camera(withLatitude: 37.778577, longitude: -122.419063, zoom: 15)
}

i expect it to move the map to the new point. but it doesn't. if i add this line to my function self.view = self.mapView it will work but it doesn't have this transition animation from one point to another but it just shows the location instantly. also i think it's not a right approach assigning the mapView to view again.

please help me to figure out why it doesn't move ?

thanks a lot!

EDIT: ps: i'm using this tutorial: link and it's on 15th minute where it adds the new location

Upvotes: 1

Views: 659

Answers (1)

Tung Fam
Tung Fam

Reputation: 8167

I resolved the issue by moving:

self.view = self.mapView

after the line:

self.mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)

I guess the reason is that I needed to assign to view after init of map.

Upvotes: 1

Related Questions