I'm trying to generate a map using the GoogleMaps SDK, I had previously generated a map using the lines "let map = GMSMapView()" and then setting the view with "self.view = map" and that worked like a charm, but then I switched over to this more complicated format used in a tutorial I am following, and even though the code is the same, mine appears to fail to generate the map :(
Any help would be amazing as I've been struggling with this for a while now and I really can't spot the issue!
//Modules
import GoogleMaps
import SwiftUI
import UIKit
import GoogleMapsUtils
class MapViewController: UIViewController, GMSMapViewDelegate, CLLocationManagerDelegate {
var mapView: GMSMapView!
let locationManager = CLLocationManager()
override func loadView() {
super.loadView() //LoadMap - Default
locationManager.delegate = self
locationManager.requestAlwaysAuthorization()
guard let myLoc = locationManager.location?.coordinate else{return}
if CLLocationManager.locationServicesEnabled() {
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.startUpdatingLocation()
}
//Camera Focus
let camera = GMSCameraPosition.camera(withLatitude: myLoc.latitude, longitude: myLoc.longitude, zoom: 15.0)
mapView = GMSMapView.map(withFrame: self.view.bounds, camera: camera)
mapView.isMyLocationEnabled = true
mapView.delegate = self
self.view = mapView
}
}
EDIT: Added swiftui bridge viewcontroller below:
import GoogleMaps
import SwiftUI
struct MapViewControllerBridge: UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> MapViewController {
let uiViewController = MapViewController()
return uiViewController
}
func updateUIViewController(_ uiViewController: MapViewController, context: Context) {
}
}