当指南针应用程序使用地图视图来显示其位置时,会有一个小锥体显示手机指向的方向。然而,我无法在显示用户位置的MKMapView中复制它。这个视野锥体功能是否可供开发者使用,还是我需要自己实现一个?
谢谢!
谢谢!
[mapView setUserTrackingMode:MKUserTrackingModeFollowWithHeading animated:YES];
- MKUserTrackingModeNone (free scrolling map)
- MKUserTrackingModeFollow (center the user's location)
- MKUserTrackingModeFollowWithHeading (center user's location and track user's heading (direction)).
MTLocation有一个很棒的图像包,其中包括你需要的锥形图标: https://github.com/myell0w/MTLocation/tree/master/Resources/MTLocation.bundle
我遇到了类似的情况。我认为我们没有库或设置来显示蓝色图标上的方向(至少我的搜索没有成功)。
但是,使用CLHeading(TommyG答案中的参考)创建自己的方向指示器并不困难。
我所做的是在地图中显示蓝色图标,并在不同视图中提供一个小箭头来指示方向。
希望这可以在某种程度上帮助。
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);
}
#import <Foundation/Foundation.h>
@interface NSFileManager (Powertools)
+ (NSString *)getCacheDirectory;
@end
在这里你可以看到 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