0

在 iPhone osm 地图应用程序(Route me)上工作。初始化和下载在线地图很容易,但真正的问题在于在线时通过代码保存图块,并在离线时重用它们。我检查了关于相同但每个人的博客正在外部保存图像并将其导入项目中然后显示它们,这不是我的要求。请帮助我保存我从在线资源中选择的平铺图像路线

 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);

    }
4

2 回答 2

1

我有一个 iOS 应用程序,它使用保存在 sqlite 数据库中的静态地图图像。有一些关于如何做到这一点的参考资料,但我花了很多试错的努力来理解它们并让它发挥作用。

似乎您应该能够拥有一个 sqlite 数据库,并在您的应用程序下载它们时将下载的图像保存到其中。然后你必须知道要使用什么平铺源:如果应用程序离线,则使用 sqlite 数据库,在线时使用 OSM 站点。

数据库的结构是:
tilekey text // route-me 用来定位正确图块的散列 zoom integer
row integer
col integer
zoom integer
image blob 这存储了地图的实际图像

我使用 Python 脚本来填充数据库,因为我希望应用程序始终使用数据库中的静态地图图像,而不是使用 OSM 的实时下载。

如果您想了解更多信息,请告诉我,但是如果您使用 route-me 搜索使用静态地图,您应该会找到这是如何完成的。祝你好运!

于 2014-01-28T17:10:51.770 回答
0
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
于 2014-01-29T11:57:45.727 回答