download Route me online tiles into database

299 views Asked by At

working on iPhone osm maps app (Route me).well initialising and downloading online maps was easy but real problem lies in saving the tiles through the code while u are online and reuse them while you are offline.i checked blogs regarding the same but everyone is saving the images externally and importing it in project and then showing them,which is not my requirement.please help me to save the tile image route me picks from online source

 here is how i am using online route me maps


 -(void) viewDidLoad
 {
    [RMMapView class];
     mapView.contents.tileSource = [[RMOpenStreetMapSource alloc] init];

    currentMarker = [[RMMarker alloc]initWithUIImage:[UIImage             imageNamed:@"radarLocatorLite.png"] anchorPoint:CGPointMake(0.5, 0.5)];
     markerManager   = [mapView markerManager];


     locationManager.delegate=self;
     locationManager.desiredAccuracy = kCLLocationAccuracyBest ;
     locationManager.distanceFilter =0;

    [mapView.contents  setZoom:17.0f];
    [markerManager addMarker:currentMarker AtLatLong:currentLocation.coordinate];
    [self initCompassView];
     [locationManager startUpdatingLocation];
     [locationManager startUpdatingHeading];

 }

-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    currentLocation =newLocation;

        [mapView moveToLatLong:newLocation.coordinate];



    [markerManager moveMarker:currentMarker AtLatLon: newLocation.coordinate];

        [currentRoutePath addLineToLatLong:newLocation.coordinate];
        [[mapView.contents overlay] addSublayer:currentRoutePath];
       //  NSLog(@"i reached  inside location update%f",currentRoutePath.lineWidth);

    }
2

There are 2 answers

0
johnz On

I have an iOS app that uses static map images saved in a sqlite database. There are some references as to how to do that, but it took me lots of trial-and-error effort to make sense of them and make it work.

It seems that you should be able to have a sqlite database and save the downloaded images into it as your app downloads them. Then you'd have to know what tile source to use: the sqlite database if the app is offline, the OSM site when online.

The structure of the database is:
tilekey text // a hash that route-me uses to locate the correct tile zoom integer
row integer
col integer
zoom integer
image blob this stores the actual image of the map

I use a Python script to populate the database, as I want the app to always use the static map images from the database, never to use a real-time download from OSM.

Please let me know if you'd like more information, but if you search for using static maps with route-me, you should find how this is done. Good luck!

0
Tanuj Jagoori On
finally resolved problem by just a minor change in few places

Step 1: Go to this site "http://shiki.me/blog/offline-maps-in-ios-using-openstreetmap-and-route-me/" and follow instructions to download tile images from online and create of zip of the folder.remember the tile images folder are in order ->zoom level folder->x coord foler->y coord image respectively.

step 2: unzip the zip file in ur app at some folder

step 3:go to the file "RMAbstractMercatorWebSource.m" in map view project
and replace the following folders 
-(NSString*) tileFile: (RMTile) tile
{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder
    NSString *path = [documentsDirectory stringByAppendingPathComponent:@"Tiles"];
    NSString *absPath=[NSString stringWithFormat:@"%@/%d/%d/%d.png", path,tile.zoom, tile.x, tile.y];
    NSLog(@"file path >>>.............%@",absPath);
    return absPath;
}//I unzipped the zip file at tiles folder 

-(NSString*) tilePath
{
    return nil;
}

-(RMTileImage *)tileImage:(RMTile)tile
{
    RMTileImage *image;

    tile = [tileProjection normaliseTile:tile];

    NSString *file = [self tileFile:tile];

    if(file && [[NSFileManager defaultManager] fileExistsAtPath:file])
    {
        image = [RMTileImage imageForTile:tile fromFile:file];
    }
    else if(networkOperations) 
    {
        image = [RMTileImage imageForTile:tile withURL:[self tileURL:tile]];     
    }
    else
    {
        image = [RMTileImage dummyTile:tile];
    }

    return image;
}
this in turns first look in cache then check the specified directory and finally go for online osm tile images