Swift Google Maps Location Direction When In Landscape Mode

154 views Asked by At

In my swift 5.7.2 and XCode 14.2 IOS app I have a simple Google Map View.

The map is showing correctly and as I move the camera is updating properly except the direction of the blue dot indicating where I'm heading when the iPhone is in landscape mode.

For example, as shown in the picture below, enter image description here

The arrow of the blue dot is pointing north. Indeed, north is the direction where the top of my phone is pointing when in portrait mode. However, if I rotate the phone, making it in landscape mode, the blue arrow is indicating exactly -90 degrees off.

I've tried using animate with a toBearing and a viewingAngle, it doesn't work properly and just rotates the map as I move around:

            var navView: GMSMapView! ## In View Controller
            var camera = GMSCameraPosition.camera(withLatitude: latitude, longitude: longitude, zoom: 1)
            let viewBounds = self.view.bounds
            navView = GMSMapView.map(withFrame: CGRect(x: 102, y: 0, width: viewBounds.maxX - 205, height: viewBounds.maxY), camera: camera)
            navView.tag = 10
            navView.isMyLocationEnabled = true
            navView.isTrafficEnabled = true
            self.view.addSubview(navView)
.....

    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        let location = locations.last!
        speed = abs(location.speed)
        altitude = location.altitude
        let coordinate = location.coordinate
        latitude = coordinate.latitude
        longitude = coordinate.longitude
        setSpeeds(speed, timeStamp: Int(UInt64(location.timestamp.timeIntervalSince1970)))
        if((navView) != nil){
            let target = CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
            navView.animate(to: GMSCameraPosition(target: target, zoom: 15, bearing: location.course, viewingAngle: 0))
        }
    }

What's the proper way of showing the correct heading when in landscape mode? Worst case scenario, if I can't forcefully set the heading +90 degrees when in landscape mode, is there a way to disable the heading and just show the blue dot?

Thanks!

0

There are 0 answers