how to show an arrow on mapview showing the driving direction
Asked Answered
A

1

8

I want to show an arrow image on GMSMapView(i am using google maps sdk). Now if i am driving(arrow is showing my current location) and i have to take left turn then i have to change bearing of mapView. But i have no idea how to do this.

I am trying to change bearing in didUpdateHeading

- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading{
if(newHeading.headingAccuracy>0)
{

    float heading = newHeading.magneticHeading; //in degrees
     //heading = (heading*M_PI/180);
    //NSLog(@"heading=%f", heading);
    [mapView animateToBearing:heading];
}}

headingFilter is set to 12.

I have also tried trueHeading, but magneticHeading is giving better results not accurate though.
Please help.

Anselma answered 2/12, 2013 at 7:28 Comment(2)
have you tried [Your CLLocationManager instance].desiredAccuracy = kCLLocationAccuracyBestForNavigation ?Brainy
yes, locationManager.distanceFilter = kCLDistanceFilterNone; locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;Anselma
O
5

You don't actually need to convert anything to degrees. The newHeading object you get from your delegate method should be enough. The GMS-reference for the animateToBearing: requires a CLLocationDirection as a parameter. The newHeading.magneticHeading or newHeading.trueHeading provided by the delegate method is an object of this type. Also: you're converting the newHeading to a float, where as a CLLocationDirection is a double, so the GMS-function will also require a double. See reference.

Onassis answered 10/12, 2013 at 13:55 Comment(4)
i am not converting it to degrees. see the code i had posted. Even [mapView animateToBearing:newHeading.magneticHeading]; is not working properlyAnselma
I'm sorry, I meant radians. Just try if(newHeading.headingAccuracy>0) { [mapView animateToBearing:newHeading]; }Onassis
have you ever tried this ?? in animateToBearing we can pass CLLocationDirection newHeading is of type CLHeadingAnselma
mapView.animate(toBearing: newHeading.magneticHeading) - works fineIddo

© 2022 - 2024 — McMap. All rights reserved.