Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS iPhone show user direction and orientation in space like the compass app on MKMapView

When the compass app uses a map view to display it's location, there's a little cone that displays the direction in which the phone is pointing. However, I was unable to reproduce it using MKMapView that shows user's location. Is this cone of sight feature available to developers, or will I have to implement one myself?

iPhone compass map app

Thank you!

like image 772
Alex Stone Avatar asked Apr 22 '12 00:04

Alex Stone


4 Answers

This is extremely easy like a piece of cake with MapKit. This is called UserTrackingMode. You have write down just one line of code to make the map become "compass-like":

 [mapView setUserTrackingMode:MKUserTrackingModeFollowWithHeading animated:YES];

In addition, there are about 3 type of UserTrackingMode:

- MKUserTrackingModeNone (free scrolling map)
- MKUserTrackingModeFollow (center the user's location)
- MKUserTrackingModeFollowWithHeading (center user's location and track user's heading (direction)).

If you're in one of 2 tracking (not free) mode, then you scroll the map out, the mode will be automatically change to free mode.

like image 182
Envil Avatar answered Nov 01 '22 18:11

Envil


I faced a similar situation. I don't think we have library or settings to display the direction on the blue icon (at least my search was not successful).

However it is not difficult to create our own direction indicator using the CLHeading (reference in TommyG's answer).

What I did was to display the blue icon as in the map and provide a small arrow in a different view to indicate the direction.

Hope this helps in some way

like image 43
zolio Avatar answered Nov 01 '22 19:11

zolio


Here is the relevant framework that you can use for this matter:

http://developer.apple.com/library/ios/#documentation/CoreLocation/Reference/CLHeading_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40008772

like image 31
TommyG Avatar answered Nov 01 '22 17:11

TommyG


MTLocation has a great bundle of images including the cone that you are after: https://github.com/myell0w/MTLocation/tree/master/Resources/MTLocation.bundle

like image 30
Helllo Ast Avatar answered Nov 01 '22 17:11

Helllo Ast