user23423753
user23423753

Reputation: 21

map(withFrame: camera) is deprecated? How do I fix this?

First time coding and trying to use the Google Maps API.

My line of code is:

let mapView = GMSMapView.map(withFrame: view.frame, camera: camera)

The error I'm getting is:

map(withFrame: camera) is deprecated. use -init or -initWithOptions instead.

Everything I've tried either doesn't work or is also deprecated:

let mapView = GMSMapView(frame: self.view.bounds, camera: camera)
let mapView = GMSMapView.map(withFrame: view.frame, camera: camera)
let mapView = GMSMapView(frame: view.bounds, camera: camera)
let mapView = GMSMapView(view.frame, camera:camera)
let mapView = GMSMapView(frame: view.bounds)
    
    

Upvotes: 2

Views: 247

Answers (2)

keshav
keshav

Reputation: 178

@IBOutlet weak var mapBaseView: UIView!
var mapView: GMSMapView?

func setMapView(){
let options = GMSMapViewOptions()
options.camera = GMSCameraPosition.camera(withLatitude:location.coordinate.latitude,
longitude: location.coordinate.longitude, zoom: currentZoomLevel)
options.frame = self.mapBaseView.bounds
mapView = GMSMapView(options: options
self.mapBaseView.addSubview(mapView ?? GMSMapView())
}
  1. Map View Declaration
  2. Options Initialisation
  3. Camera Setup
  4. Give frame
  5. add subview

Upvotes: 1

vivek mittal
vivek mittal

Reputation: 1

I faced this challenge before as well. This might help you:

let options = GMSMapViewOptions()
options.camera = camera
    
let mapView = GMSMapView.init(options: options)

enjoy :)

Upvotes: 0

Related Questions