Bearing of Current location in iOS SDK
Asked Answered
S

2

10

I have just completed an Android app, where I used bearing value of current location. Now I am trying to do same app for iOS. But did not find a way to get bearing of current location in iOS sdk?

I am not looking how to calculate bearing between two CLLocationCoordinate2Ds (Calculating bearing between two CLLocationCoordinate2Ds).

*** I need bearing of current location.

Any help will be great for me.

Somatic answered 10/5, 2013 at 9:29 Comment(4)
dont see what you mean.. how can one location have a bearing? you need a TARGET to have a bearing toEla
post your code that you triedBicarbonate
In Android I used: currentBearing = currentLocation.getBearing();Somatic
@Somatic can u please check my problem #43589365Lorianne
G
18

CLLocation has a course property (type CLLocationDirection) which is the bearing. From the docs:

Course values are measured in degrees starting at due north and continuing clockwise around the compass. Thus, north is 0 degrees, east is 90 degrees, south is 180 degrees, and so on. Course values may not be available on all devices. A negative value indicates that the direction is invalid.

Gomphosis answered 10/5, 2013 at 10:40 Comment(6)
Thank you, @nevan king. I think I got my answer that I was looking for.Somatic
can to tell me how to use this course property @SomaticSupra
@nevan king. I am working with marker rotation in google maps, How can i set rotation for that, can u please guide me.Periodontal
@ nevan king Im getting course property. Im applying directly gmsmap view bearing. Is it correct or shall i need to apply for marker.rotation also .. Can u please check my problemLorianne
I tried to use the same value, but I am always getting -1, am I doing something wrong? @SomaticMaestro
@ParasGorasiya it's been a while since your comment, but I'm experiencing the same outcome (-1). Did you manage to get to the bottom of that mystery?Manana
C
0

I know that this question is old but I will leave my answer that may help other people who pass by here.

class MapViewController: GMSMapViewDelegate {

    func mapView(_ mapView: GMSMapView, idleAt position: GMSCameraPosition) {

        self.bearing = position.bearing
    }
}

Using this delegate you can obtain the bearing related with camera rotation from the google maps SDK.

Cowskin answered 10/3, 2019 at 21:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.