graphhopper / graphhopper-ios

iOS Port of the GraphHopper road routing engine
https://www.graphhopper.com/open-source/
Apache License 2.0
69 stars 28 forks source link

Unable to load graph downloaded from an external web site #14

Closed ugochirico closed 8 years ago

ugochirico commented 8 years ago

I created graph-data.osm.gh following the usual way. If I embed that graph in the app bundle it works perfectly. Then I put that graph on my web site and I downloaded it from the app, storing it in the document folder but graphhopper is unable to load that graph.

This is the document directory:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString* graphPath = [documentsDirectory stringByAppendingPathComponent:@"graph-data.osm-gh"];

I check if the file "properties" exists:

BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:[graphPath stringByAppendingPathComponent:@"properties"]];
NSLog(@"exists %@, %d", [graphPath stringByAppendingPathComponent:@"properties"], exists);

this is the result: exists /var/mobile/Containers/Data/Application/ADF41477-E25E-4173-B896-75AE8F491603/Documents/graph-data.osm-gh/properties, 1

the file "properties" exists!

Then I try to load the graph in graphhopper:

_hopper = [[GraphHopper alloc] init];
[_hopper setCHEnableWithBoolean:YES];
        [_hopper setAllowWritesWithBoolean:NO];
        [_hopper setMemoryMapped];
        [_hopper setEncodingManagerWithEncodingManager:[[EncodingManager alloc] initWithNSString:@"car"]];
        jboolean loaded = [_hopper load__WithNSString:location];
        NSLog(@"Loaded: %d", loaded);

I got loaded is false; I went in debug inside graphopper and I see that it fails when it tries to load "properties" file in MMapDataAccess.m, in loadExisting function:

JavaIoFile *file = [[[JavaIoFile alloc] initWithNSString:[self getFullName]] autorelease];
NSLog(@"file %@ exists %d, %u", [self getFullName], [file exists], [file length]);

The log is: 2016-09-09 18:26:23.076 UcciNav[1539:118823] file /var/mobile/Containers/Data/Application/9204D3BE-5AFB-4908-B784-04CA959A2DCA/Documents/graph-data.osm-gh/properties exists 0, 0

"properties" file doesn't exists. Pay attention, the first log says:

exists /var/mobile/Containers/Data/Application/ADF41477-E25E-4173-B896-75AE8F491603/Documents/graph-data.osm-gh/properties, 1

the last one says:

2016-09-09 18:26:23.076 UcciNav[1539:118823] file /var/mobile/Containers/Data/Application/9204D3BE-5AFB-4908-B784-04CA959A2DCA/Documents/graph-data.osm-gh/properties exists 0, 0l

Application IDs are different!!! This is why Graphhopper cannot find the file. Why? the app is the same, but in graphhopper core the absolute path is different.

Any suggestion?

ugochirico commented 8 years ago

Sorry, it was my mistake in saving the graph in the wrong document directory. It works like a charm. Sorry to disturb you.

karussell commented 8 years ago

Still thanks for reporting, you can also use our forum