cordova-plugin-mbtiles icon indicating copy to clipboard operation
cordova-plugin-mbtiles copied to clipboard

mbTilesPlugin.open Returns Null

Open egmobile opened this issue 8 years ago • 2 comments

We used the following command to open an off-line map in iOS and Android but since our last upgrade in cordova it fails (only in iOS) returning null.

App.mbTilesPlugin.open({name: 'NoCloud/map/map.mbtiles'},.......

egmobile avatar Aug 03 '16 17:08 egmobile

Sorry for the delay of response.

I don't use the plugin since a long time ago, so maybe in an upgrade of iOS something change for security or permission for the databases or path.

You must debug the plugin for ios by xCode to know why the database can't be open.

Sorry but i lost my mac and i can't help you.

ffournier avatar Nov 13 '16 15:11 ffournier

I'm not sure, whether this is still an issue. I had problems using this plugin in iOS yesterday. I tried to load a map but did not get any response, neither a positive one nor an error. So I started debugging the plugin source which resulted in the following changes in MBTilesActionsDataBaseImpl.m

- (void)open:(NSString*) name {
    
    [self close];
    
    NSFileManager *filemgr =  [NSFileManager defaultManager];
    NSString* dir = [self getFullDirectory];
    if (dir != nil) {
        NSString *absolutePath = @"";
       // This inner if statement opens the posibility to use the function with absolute path
       // to mbtiles file. The replacement in the else part is due to the place I store my
       // files after transfer...
        if ([[name substringToIndex:1]  isEqual: @"/"]) {
            absolutePath = name;
        } else {
            dir = [dir stringByReplacingOccurrencesOfString:@"Documents" withString:@"Library"];
            dir = [dir stringByReplacingOccurrencesOfString:@"tiles" withString:@"NoCloud"];
            absolutePath = [dir stringByAppendingPathComponent:name];
        }
        

        // test if the file exist
        if ([filemgr fileExistsAtPath: absolutePath ] == YES) {
            const char *dbpath = [absolutePath UTF8String];
            // open the database
            if (sqlite3_open_v2(dbpath, &_database, SQLITE_OPEN_READONLY, NULL) != SQLITE_OK) {
                _database = nil;
            }
        } else {
            _database = nil;
        }
    }
}

[self getFullDirectory] results in a directory named /<appDirectory>/Documents/tiles/ Since I use file transfer functions to place the file, my mbtiles were not in this place. You might want to check, whether this directory matches your mbtiles location.

Might help someone. :)

stihl-sicher avatar Jun 27 '17 06:06 stihl-sicher