IOS: using offline maps

in my application I want to use standalone maps, and with these maps use gpx files to have a route. I found openstreetmap to do this, but are there any better services? (best solution with level curves) thanks

+7
source share
4 answers

Offline maps require a bit of iOS experience, as there are not many projects and examples. However, you have one project called Route-Me that can give you a starting point. We used it to develop the Metro Valencia Offline , which successfully ended up on the App Store. I wrote a short tutorial on how to add Route-Me to your project.

Basically, you can use any map feed you might need (OpenStreetMaps is one of them, as well as the one we used). You will need to do the following:

+9
source

You can also check: skobbler's / Telenav: http://developer.skobbler.com/support#download it is based on OpenStreetMap, and they got full autonomous features (GPX track tracking, map rendering, routing and redirection)

+2
source

There is also the Nutiteq Maps SDK: http://developer.nutiteq.com , standalone maps for iOS and Android, supports the Xamarin IDE (C #) and native languages ​​(Java, ObjectiveC, Swift). This is not so much routing and navigation (as, for example, Skobbler), but more for those focused on complex maps with interactive layers (points, lines and polygons on top of maps). One of the advantages is that you can use your own sources of the base card (your own, third parties), and not just the OpenStreetMap that the SDK itself provides.

Disclaimer: I'm a developer.

+1
source

I used the default map from MapKit and a subclass of MKTileOverlay to be able to save downloaded fragments and return already cached fragments without loading them.

1) Change the source for your default map from MapKit and use the MKTileOverlay subclass (here an "open street map" is used)

- (void)viewDidLoad{ [super viewDidLoad]; static NSString * const template = @"http://tile.openstreetmap.org/{z}/{x}/{y}.png"; VHTileOverlay *overlay = [[VHTileOverlay alloc] initWithURLTemplate:template]; overlay.canReplaceMapContent = YES; [self.mapView addOverlay:overlay level:MKOverlayLevelAboveLabels]; } 

2) subclass from MKTileOverlay

 @interface VHTileOverlay() // MKTileOverlay subclass @property (nonatomic, strong) NSOperationQueue *operationQueue; @end @implementation VHTileOverlay -(instancetype)initWithURLTemplate:(NSString *)URLTemplate{ self = [super initWithURLTemplate:URLTemplate]; if(self){ self.directoryPath = cachePath; self.operationQueue = [NSOperationQueue new]; } return self; } -(NSURL *)URLForTilePath:(MKTileOverlayPath)path { return [NSURL URLWithString:[NSString stringWithFormat:@"http://tile.openstreetmap.org/%ld/%ld/%ld.png", (long)path.z, (long)path.x, (long)path.y]]; } -(void)loadTileAtPath:(MKTileOverlayPath)path result:(void (^)(NSData *data, NSError *error))result { if (!result) { return; } NSString *pathToFilfe = [[self URLForTilePath:path] absoluteString]; pathToFilfe = [pathToFilfe stringByReplacingOccurrencesOfString:@"/" withString:@"|"]; // @"/" - those are not approriate for file url... NSData *cachedData = [self loadFileWithName:pathToFilfe]; if (cachedData) { result(cachedData, nil); } else { NSURLRequest *request = [NSURLRequest requestWithURL:[self URLForTilePath:path]]; __block VHTileOverlay *weakSelf = self; [NSURLConnection sendAsynchronousRequest:request queue:self.operationQueue completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) { NSLog(@"%@",[weakSelf URLForTilePath:path]); if(data){ [self saveFileWithName:[[weakSelf URLForTilePath:path] absoluteString] imageData:data]; } result(data, connectionError); }]; } } -(NSString *)pathToImageWithName:(NSString *)fileName { NSString *imageFilePath = [[OfflineMapCache sharedObject].cachePath stringByAppendingPathComponent:fileName]; return imageFilePath; } - (NSData *)loadFileWithName:(NSString *)fileName { NSString *imagePath = [self pathToImageWithName:fileName]; NSData *data = [[NSData alloc] initWithContentsOfFile:imagePath]; return data; } - (void)saveFileWithName:(NSString *)fileName imageData:(NSData *)imageData { // fileName = [fileName stringByReplacingOccurrencesOfString:@"/" withString:@"|"]; // NSString *imagePath = [self pathToImageWithName:fileName]; // [imageData writeToFile:imagePath atomically:YES]; } 

Uncomment "saveFileWithName" and run it on the simulator. You can also add NSLog (file_name) to find out where to get all the tiles you need. (The simulator cache is in User / YOU / Library / Developer / CoreSimulator / Devices / ... And the library is a hidden directory)

After you have cached everything you need, just add to your application suite (like any other image, if you want, using the cache card). And say

 - (void)loadTileAtPath:(MKTileOverlayPath)path result:(void (^)(NSData *data, NSError *error))result 

to get fragments from the package.

So, now I can install the application, turn off Wi-Fi, and still get these cards.

0
source

All Articles