I am using a Google Maps Street View in Swift and am trying to find a way to add a compass button or a constant compass.
Simply put, as the user clicks and travels through the streets on the screen, if they hit the compass button at any time it will display their current compass heading (IE: North East).
I have a simple view attached to an outlet:
@IBOutlet weak var panoramaView: GMSPanoramaView!
Loaded like:
panoramaView.moveNearCoordinate(CLLocationCoordinate2D(latitude: latitude, longitude: longitude))
It seems there is an option for a compass if you are using other types of map views but I can find any options for a compass on GMSPanoramaView.
I can get the users current position using:
func panoramaView(_ view: GMSPanoramaView, didMoveTo panorama: GMSPanorama?) {
//print("Current Position: \(panorama?.coordinate.latitude ?? 0.0)")
latitude = panorama?.coordinate.latitude ?? 0.0
longitude = panorama?.coordinate.longitude ?? 0.0
}
The rest I am stumped with. Those seem to be the only variables I can access. Does anyone know how I would move forward and turn this into a compass heading?
Any help would be greatly appreaciated.
use
GMSPanoramaCameraClass to obtain theheadingvaluesAs per the reference documentation, the
GMSPanoramaCameraClass has anorientationproperty which groups togetherheadingandpitch.Here's a method you can try out to get the
orientationvalues whenever you move your camera:console output:
Documentation states that the
Headingdefines the rotation angle around the camera locus in degrees relative from true north. Headings are measured clockwise: true north is 0, east is 90, south is 180, west is 270.With this, I believe you will be able to make conditionals to print if it is either North, East, South, West, or anything in between. Then integrate it with your button by storing the latest state.
I hope this helps!