Using offline database in Route-Me - iphone

I'm trying to use an offline MBTiles database using Route-Me. To accomplish this, I'm using Landez, which in turn depends on MBUtil.
Right now, all I get is a gray screen with the pins in their proper locations. Here's what gets printed to the console:
initializing memory cache <RMMemoryCache: 0x4e42e50> with capacity 32
Opening database at /Users/chrislong/Library/Application Support/iPhone Simulator/4.3.2/Applications/E53BC885-1B02-4B06-B45B-408EB9A147DE/Documents/MapOpenStreetMap.sqlite
Map contents initialised. view: MapView at 0,0-320,411 tileSource <RMCachedTileSource: 0x4e428b0> renderer <RMCoreAnimationRenderer: 0x4e13dc0>
initializing memory cache <RMMemoryCache: 0x5929930> with capacity 32
Opening database at /Users/chrislong/Library/Application Support/iPhone Simulator/4.3.2/Applications/E53BC885-1B02-4B06-B45B-408EB9A147DE/Documents/MapMBTilestiles.mbtiles.sqlite
Warning: I could not find the column named 'tile_data'.
Warning: I could not find the column named 'tile_data'.
Warning: I could not find the column named 'tile_data'.
Warning: I could not find the column named 'tile_data'.
Map contents initialised. view: MapView at 0,0-320,411 tileSource <RMCachedTileSource: 0x592a400> renderer <RMCoreAnimationRenderer: 0x5925770>
It's worth noting that the file is named tiles.mbtiles, not MapMBTilestiles.mbtiles.sqlite, and is stored in the root of the bundle, not the Documents folder.
Here's the code I use to make the mapView and load the database:
CLLocationCoordinate2D center = {50, 50};
self.mapView = [[[RMMapView alloc] initWithFrame:self.view.frame] autorelease];
self.mapView.backgroundColor = [UIColor blackColor];
self.mapView.delegate = self;
NSURL *tilePath = [[NSBundle mainBundle] URLForResource:#"tiles" withExtension:#"mbtiles"];
RMMBTilesTileSource *tiles = [[[RMMBTilesTileSource alloc] initWithTileSetURL:tilePath] autorelease];
[self.mapView.contents removeAllCachedImages];
self.mapView.contents = [[[RMMapContents alloc] initWithView:self.mapView tilesource:tiles centerLatLon:center zoomLevel:0.0 maxZoomLevel:[tiles maxZoom] minZoomLevel:[tiles minZoom] backgroundImage:nil] autorelease];
[self addMarkers];
Route-Me is obviously not reading the file at all; even if I delete the database entirely, I get the same log output. IOW, the problem is probably as a result of Route-Me being unable to find the file. Any help would be appreciated!

Check out - (RMTileImage *)tileImage:(RMTile)tile from MapView->Map->Tile Source
I was having some issues with sqlite db's generated by map2sqlite until I changed the line:
NSInteger y = pow(2, zoom) - tile.y - 1;
to:
NSInteger y = tile.y;
I'm using tilemill generated db's right now, so I haven't dug into it further, but I'd toss in some debug statements if I were you and look at what tiles its looking for vs what the tile layout in your db is. I think it might have to to do with mbtiles tiling order vs osm's tiling order.
-- Randy

I actually wrestled with this very problem yesterday.
There seem to be two different tile formats out there, google xyz and TMS which is used by openstreetmap.
The line Randy highlighted
NSInteger y = pow(2, zoom) - tile.y - 1;
Is converting one to the other. So for example I am building my map using Maperative, then exporting it to tiles in a directory and finally using mb-util to generate the tiles.mbtiles file.
And I was having the exact same issue, make the changes that Randy suggested above and it works.
ultimately however I wrote a php script to rename the filenames of the tiles to be correct. I'll be honest I still haven't quite got my head around which pieces of software are exporting in what format. I think mbtiles is supposed to be TMS which implies that route-me is xyz, but I could be wrong on that.

I made your change above but then had some problems centering the map. After working on it for quite some time I change the line you mention above to this:
NSInteger y = tile.y - (pow(4, ((zoom / 2) - 1)));
Hope this helps anyone also having trouble.

Related

Displaying google direction api response on Map

I am using google api V3 in my iOS App,
I requested to google api direction service, by http GET method, I got a very large json response, I got many alternate routes from origin to destination, now I want to show the route of each alternative on map, how should I done this ? is there any need to integrate google sdk in iOS, or can i use webView only, please help me, and suggest the simplest way.
Thanks in advance
you do not need to include any google SDK to draw the route over map. Look at the following classes.
MKPolyline
MKPolyLineview
The google map api Direction service will give you the legs(coordinates) to draw the route between two specific points.
As you already have the json response from the Direction api now you have to parse the json and get all the legs point from the json to create Coordinate array.
Jsonkit for parsing
These points may be or mostly encripted. How to decode the Google Directions API polylines field into lat long points in objective-C for iPhone?
If you have the coordinates array then first you have to create a CLLocationCoordinate2D array like following:
CLLocationCoordinate2D *pointArr = malloc(sizeof(CLLocationCoordinate2D) * [your_CoordinateArray count]);
for(int i = 0; i < [your_CoordinateArray count]; i++){
pointArr[i] = [your_CoordinateArray objectAtIndex:i];
}
Then you have to add the polyline to your map
MKPolyline *line = [MKPolyline polylineWithCoordinates:pointArr count:[your_CoordinateArray count]];
if (nil != line)
{
[your_Map addOverlay:line];
}
Then you have to implement the following map delegate:
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
MKOverlayView* overlayView = nil;
lineView = [[MKPolylineView alloc] initWithPolyline:overlay];// lineView is an ivar, object of MKPolylineView
lineView.fillColor = [UIColor greenColor];
lineView.strokeColor = [UIColor greenColor];
lineView.lineWidth = 10.0;
lineView.alpha = 0.9;
overlayView = lineView;
return overlayView;
}
Now, if you want to show two different routes between two points then you have to create two different array of coordinates and apply the above method for both Arrays
Hope this will help you.
There is no need per say to integrate google sdk and you can simply use webView since I believe the webView gives you alternative views, but the user interface is much cleaner in the SDK than online. But at this moment, I don't believe the SDK allows other apps to show the alternative routes from what I've used of the new SDK. The code in maps.google.com is now considerably different from that in
the API and has access to different services. In particular, it has a large external module, mod_suggest.js, that doesn't exist in the API. But you may be able to implement it by
1) Throw the request at maps.google.com, and let it do the suggestions,
i.e. open a new browser window and pass it something like
http://www.google.com/maps?f=d&source=s_d&saddr=Jurong+West,+Singapore&da
ddr=Ang+Mo+Kio,+Singapore&hl=en
2) Just display the normal route and the avoid highways route.
3) Try to guess sensible waypoints to add in the middle of he route that
might lead to reasonable alternatives. That's not easy unless you have a
database of highways or highway intersections, and can look for such an
intersection that's somewhere between your start and end points (for
some approximate value of "between").
There may be problems using lat/lng coordinates for the waypoints,
particularly if there's a dual carriageway involved. If the coordinates
are for a point on the wrong carriageway, GDirections will drive a
considerable distance out of your way so that you visit the wrong side
of the road. But even using street names you may well get strange kinks
near the waypoints, like this:
from: Jurong West, Singapore to: Ayer Rajah Expy singapore to: Ang Mo
Kio, Singapore
Perhaps the only way to really deal with that is to include points on
both sides of a dual carriageway, and well clear of roads that cross
underneath or overhead, and then try to filter out the ones that are
silly.
Consider these examples
from: Jurong West, Singapore to: 1.32558,103.740764 to: Ang Mo Kio,
Singapore
from: Jurong West, Singapore to: 1.32582,103.740764 to: Ang Mo Kio,
Singapore
One of those adds 7 minutes to the trip by a complicated excursion to
visit the wrong side of the road.
Writing code to filter out silly routes isn't easy. As a first
approximation, you could discard routes that have estimated times that
are more than, say, 10% longer than the initial route. And you can also
compare the durations for pairs of points on opposite sides of a dual
carriageway and always discard the slower one.
Writing code to discard duplicate routes isn't easy either. For example,
a point on Bukit Timah Expy or Kranji Expy might create a route that's a
duplicate of Google's Seletar Expy suggestion.
You might want to look at: http://www.geocodezip.com/example_geo2.asp?waypts=yes&addr1=Jurong+West,+Singapore&addr2=Ang+Mo+Kio,+Singapore&waypt=Ayer+Rajah+Expy+singapore&geocode=1&geocode=2
But that may not be a legal implementation since the API does not allow it. Hope this helps.

How to load Vuforia QCAR tracking file data during runtime in iOS

I am working on Augmented reality using Vuforia sdk, and i want to load 3d object on runtime, i want to fetch it from web-service and load it when i need that, So basically my question only is this how can we load any .h file on run time. First is this possible that we can load it on runtime and if possible then how can we do that.
If you have dynamic data, putting it into a .h file doesn't make sense. Headers are only useful while the program is being compiled, not at run time.
AFAIK vuforia just puts arrays of vertical, triangles, etc. into h file. So you don't need to load h file in runtime (and this is impossible, there is no h files when programm is running). Instead you need to get those arrays and give them to vuforia
just download that file from network, store it within application directories and load it like the sample data bundled with the app
NSString * pathToDownloadedFile; //should have path to your file
QCAR::DataSet *dataSet = nil;
QCAR::TrackerManager& trackerManager = QCAR::TrackerManager::getInstance();
QCAR::ImageTracker* imageTracker = static_cast<QCAR::ImageTracker*> (trackerManager.getTracker(QCAR::Tracker::IMAGE_TRACKER));
dataSet = imageTracker->createDataSet();
dataSet->load([pathToDownloadedFile cStringUsingEncoding:NSASCIIStringEncoding], QCAR::DataSet::STORAGE_ABSOLUTE);
imageTracker->activateDataSet(dataSet);

json vs xml annotations for mapkit

I have been working on a maps application (iphone) originally I had my annotations set up to pull XML from google using their Places API. I'm having 3 issues.
For my annotation info, I was going
off of an example from Zen
(http://www.zen-sign.com/finding-business-listings-and-displaying-with-mapkit-part-1/
) and he has it set up to do it by
keyword, which wasn't really
necessary for me ( but I used it
anyway just to get a feel for
getting the annotations) in the
parser header he has:
-(void) getBusinessListingsByKeyword:(NSString*)keyword atLat:(float)lat atLng:(float)lng;
and in the the viewdidload of his
view controller
[locationsMap findLocationsByKeyword:#"Apple" ];
I'm not sure how to move from the
keyword parse version used in zen to
something that just does it
automatically (in the parser object- without the viewdidload in a different view controller if possible).
Any advice on what to read/watch or
sample code much appreciated
For places information
Google isn't the only kid on the
block and XML I hear comes in second
to JSON. So I wanted to know what
the best practice was for map
annotations made from business
information: JSON or XML?
The other issue I was having was
only getting 10 annotations (I want
to get 50 or more). So on top of
your advice on using XML or JSON.
How to I increase the amount of
annotations I'm getting.
Sorry for making this 3 parts but again any tutorials (text of video) would be very helpful. (So far I've watched hegarty from Stanford, Larson from MATC)
First
Don't know what you mean by automaticaly. But if you want to launch the map on users current location here you have two methods you can use:
-(IBAction)goToCurrentLocation{
CLLocation *location = [[CLLocation alloc]
initWithLatitude:myMap.userLocation.coordinate.latitude
longitude:myMap.userLocation.coordinate.longitude];
[self setCurrentLocation:location];
}
- (void)setCurrentLocation:(CLLocation *)location {
MKCoordinateRegion region = {{0.0f, 0.0f}, {0.0f, 0.0f}};
region.center = location.coordinate;
region.span.longitudeDelta = 0.15f;
region.span.latitudeDelta = 0.15f;
[self.myMap setRegion:region animated:YES];
}
Second. I don't know what are the best practicies but I used json with this jeson parser for my app ijustmadelove
Three. There is no problem in getting more then 10 annotations on the map. You have to have an error or a limitation in your code.

How do I extract pixel data from DICOM files on iOS?

Does anyone know how I can extract the pixel data from a DICOM file and pass it to an image viewer on iOS?
Sorry if this is a simple question, but it seems to be a major component to a huge can of worms I have opened.
I'm using GDCM on iOS. I haven't pushed it very hard yet but it's working well so far. I basically followed the directions for hacking XCode projects to run in iOS in this excellent article on ITK.
Here's how I got it to compile for iOS:
Downloaded source from sourceforge, installed cmake via ports. You'll need a recent version of cmake (I'm using 2.8.2)
If the source is in a folder called gdcm-2.0.17/, then create another directory at that level (say gdcmbin), cd to that directory, and enter ccmake -GXCode ../gdcm-2.0.17/ in the terminal window. This creates the XCode project. When I did this I didn't create any of the example programs or create shared libraries (which won't work in iOS). Just run the defaults.
Follow the directions in the ITK paper on changing the build options (step #7 on page 4).
Then link GDCM into your project using the excellent instructions at Clint Harris' blog
When you're setting up the header search path in your project to GDCM - you have to enter two paths: blah/gdcm-2.0.17/Source/** and blah/gdcmbin/**. The trailing '/Source' on the first path is necessary - otherwise you get headers that aren't appropriate for your architecture.
One glitch (annoying but haven't spent the time to figure it out yet): you get a bunch of linking errors when you switch from simulator to device (or vice versa). This is because the gdcm project doesn't put the outputs into different directories for different targets. So - run a clean and rebuild in the gdcm project when you're switching. I'll probably get annoyed by this soon enough to change it :-).
Here's a rough snippet of how you'd call the library and put the results in an Objective-C dictionary:
NSMutableDictionary * imageDictionary = [[NSMutableDictionary alloc] initWithCapacity:40];
// The output of gdcm::Reader is a gdcm::File
gdcm::File &file = reader.GetFile();
// the dataset is the the set of element we are interested in:
gdcm::DataSet &ds = file.GetDataSet();
const Tag studyInstance(0x0020,0x000d); // Study Instance UID
const DataElement &dicomVal = ds.GetDataElement(studyInstance);
std::string stringVal( dicomVal.GetByteValue()->GetPointer(), dicomVal.GetByteValue()->GetLength() );
NSString *val = [NSString stringWithCString:stringVal.c_str() encoding:[NSString defaultCStringEncoding]];
[imageDictionary setObject:val forKey:#"studyInstanceUID"];
(Note: this is in an *.mm file that mixes C++ and ObjectiveC)
Imebra has an Objective-C wrapper that can be used also with Swift.
#import "imebraobjc/imebra.h"
// Get the DICOM dataset from file
NSError* error = nil;
ImebraDataSet* pDataSet = [ImebraCodecFactory loadFromFile:#"test.dcm" error:&error]
// CHeck the patient name (automatically convert from DICOM charsets to UTF-8)
NSString* checkPatientName = [pDataSet getString:[[ImebraTagId alloc] initWithGroup:0x10 tag:0x10] elementNumber:0 error:&error]; // Automatically converted to UTF-8 if necessary
// Get the frame 0
ImebraImage* pCheckImage = [pDataSet getImageApplyModalityTransform:0 error:&error];
// Get the image data
ImebraReadingDataHandlerNumeric* readingDataHandler = [pCheckImage getReadingDataHandler:&error];
// Scan the pixels. Access the data handler memory for faster data access
for(unsigned int pixel(0); pixel != readingDataHandler.size; ++pixel)
{
unsigned int pixelValue = [readingDataHandler getUnsignedLong:pixel error:&error];
}
ImebraDrawBitmap* pDrawBitmap = [[ImebraDrawBitmap alloc] init];
// Obtain a NSImage (UIImage on iOS)
NSImage* pNsImage = [pDrawBitmap getImebraImage:pCheckImage error:&pError];
If you want to find DICOM software, look at idoimaging.com, a clearinghouse for medical imaging software. You can choose your platform, input format, output format, language, etc. iOS isn't listed as a format, but much of the software listed there is available with source, useful in library form, and available for MacOS X. For example, I selected:
input format: DICOM
platform: Macintosh
language: C
and found several packages. Given the similarities between MacOS and iOS and the fact that some of these are cross-platform with source included, it shouldn't be too difficult to get one of them working on iOS.

How to effectively draw Polyline using Google API?

i'm drawing polyline on MapView using "google direction API" and getting success in it.But the thing is that it draws straight line between two locations(with their longitude and latitude).I don't know how to draw line effectively like shown by google maps,when we click "get directions" between two locations.
I suggest taking a look at an SDK like CloudMade, this makes it very easy to implement custom maps and route's, you'll be able to draw a route between two locations within about 10 minutes of installing the SDK. Here is a quick example to get you started if you go down this route, excuse the pun.
CLLocationCoordinate2D initLocation;
initLocation.longitude = -0.127523;
initLocation.latitude = 51.51383;
CLLocationCoordinate2D destination;
destination.longitude = -0.125;
destination.latitude = 51;
TokenManager* tokenManager = [[TokenManager alloc] initWithApikey:#"YOUR API KEY"];
CMRoutingManager *routeManager = [[CMRoutingManager alloc] initWithMapView:mapView tokenManager:tokenManager];
[routeManager findRouteFrom:initLocation to:destination onVehicle:CMVehicleWalking];
You can find more information here in the documentation. Another alternative would be to use route-me which would allow you to choose from the following map sources:
OpenStreetMap, Microsoft VirtualEarth, CloudMade, OpenAerialMap, OpenCycleMap, SpatialCloud, and two offline, database-backed formats (DBMap and MBTiles)
Although personally i do not have any experience with route-me, so can't point you in the right direction to get started.
If you are adement on sticking with MKMapView, this blog post will get your started in the right direction.