Sina
Sina

Reputation: 45

Swift 3: Google Maps Api not changing camera view

Hey so I'm trying to change the location of the map camera though a method, however when I run the program nothing happens.

func SearchConfirmed (d1: Double, d2: Double){

    print(d1 , " ", d2)
    locationManager.stopUpdatingLocation()
    let camera = GMSCameraPosition.camera(withLatitude: d1, longitude: d2, zoom: 15)
    mapView?.animate(to: camera)

}

When this method is called it is able to print the lat and lng but it doesn't change the location.

Upvotes: 2

Views: 868

Answers (2)

Sina
Sina

Reputation: 45

I figured it out, because I was calling it from another method, it created an instance of this view controller and changed the view in the instance. However because I was not displaying the instance nothing happened. To solve it I just ran all the code in the view controller and didn't call the method from another place.

Upvotes: 1

AtaerCaner
AtaerCaner

Reputation: 712

Try the GMSCameraUpdate after create a map

let camera = GMSCameraPosition.camera(withLatitude: firstLtd, longitude: firstLng, zoom: zoomScale)
let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)

When you want the update camera position;

let newCoor = CLLocationCoordinate2D(latitude: (newLtd)!, longitude: (newLng)!)
 let newCoorCam = GMSCameraUpdate.setTarget(newCoor)
 mapView?.animate(with: newCoorCam)

Upvotes: 1

Related Questions