IOS iPhone shows the direction and orientation of the user in space, for example, a compass application on MKMapView

When the compass app uses the map view to display its location, there is a small cone displaying the direction the phone is pointing. However, I was not able to play it using MKMapView, which shows the user's location. Is the cone function available to developers, or should I implement it myself?

iPhone compass map app

Thank!

+5
source share
5 answers

I faced a similar situation. I do not think that we have a library or settings for displaying directions on a blue icon (at least my search was not successful).

CLHeading ( TommyG).

, , , , .

,

+1

, MapKit. UserTrackingMode. , "":

 [mapView setUserTrackingMode:MKUserTrackingModeFollowWithHeading animated:YES];

, 3 UserTrackingMode:

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

2 ( ), , .

+4

, "imageTexture.jpg", . "FavoritePhoto.jpg" . , .

    NSError *errorDesc;

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *statesDescriptionPath = [documentsDirectory stringByAppendingPathComponent:@"FavoritePhoto.jpg"];

    NSFileManager *fileManager = [NSFileManager defaultManager];

    NSString *cacheDirectory = [NSFileManager getCacheDirectory];
    NSString *temporaryPath = [cacheDirectory stringByAppendingPathComponent:@"imageTexture.jpg"];

    NSURL *originalURL = [NSURL fileURLWithPath:statesDescriptionPath];
    [fileManager replaceItemAtURL:originalURL withItemAtURL:[NSURL fileURLWithPath:temporaryPath] backupItemName:nil options:NSFileManagerItemReplacementUsingNewMetadataOnly resultingItemURL:&originalURL error:&errorDesc];

    if (errorDesc)
    {
        NSLog(@"there was an error overwriting the favorite photo: %@", errorDesc.description);
    }

NSFileManager,

Here is the code for NSFileManager + Powertools.h

#import <Foundation/Foundation.h>
@interface NSFileManager (Powertools)
+ (NSString *)getCacheDirectory;
@end

Here you can see the code for NSFileManager + Powertools.m

#import "NSFileManager+Powertools.h"

@implementation NSFileManager (Powertools)

+ (NSString *)getCacheDirectory
{
    NSString *path = nil;
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
        if ([paths count])
        {
            NSString *bundleName =
            [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"];
            path = [[paths objectAtIndex:0] stringByAppendingPathComponent:bundleName];
        }
        return path;
}
@end
-1
source

All Articles