Graphhopper, osmdroid for osmdroid offline routing - android

I have been messing around for a while with osmdroid and osm bonus pack(amazing libs!), and have been pondering on the idea of offline routing and turn by turn navigation, now, I haven't tried anything yet, but something sounds very promising in throwing graphhopper in on the mix:
The official Wiki guide is as following:
Download a raw map file(.osm, .osm.pbf, etc.).
Run ./graphhopper.sh import map_file
Now, this is designed to work with MapsForge, and I haven't had the chance to check out the resulting .ghz file, containing the routing data for the map, BUT my question is this, could it be possible to use this routing data to build a PathOverlay object coming in OSM Bonus Pack to actually draw routes of some kind?
I wonder if someone already tried something of this sort and has something to say about it, any help appreciated.

Using Mapsforge in osmdroid: holy grail, never-ending story...
You can have a look at this (long) thread: https://groups.google.com/forum/#!topic/osmdroid/gSieR9BF_z0
There is also this working experiment: http://www.salidasoftware.com/how-to-render-mapsforge-tiles-in-osmdroid/
Now, if you really NEED offline routing, your options are:
You leave osmdroid/OSMBonusPack and move to Graphhopper/Mapsforge, as suggested by Karussell => you will find docs on Graphhopper web site.
Or you can have a look at OsmAnd. This is an app, not a lib. It has its own vector-based maps format (and toolset) and provides offline display and offline routing.
Or you can try to reach the holy grail, and merge Mapsforge, osmdroid, Graphhopper, and OSMBonusPack...

The holy grail is possible, you can use osmdroid with vector maps and yes, GraphHopper works on Android, but be ready for OOM on low-end devices - GraphHopper requires a lot of memory.
My sample project should be a good point to start.

Related

navigation app with a different route finding algorithm

I wish to make an android app that leverages OSM services and runs an algorithm of my choice to find the route, say A* or some heuristic on Dijkstra.
The Routing wiki page of OSM has some good pointers but it does not give any insight about how to go about implementing your own algorithm in the app.
This response is overview which might help you to orient better in the landscape and find a way to approach the problem. Your question is too broad to give an exact simple answer but I do understand why are you asking such question.
You can use Osmdroid library to display the route you have on Android.
Keep in mind that the core feature of Osmdroid is to display the map tiles. Map tiles are just bitmaps so you need either an online source of tiles or an offline one. How to do that is covered in the documentation and partly in other questions on SO. It's a too big topic to explain it here in detail. Just to make it clear: .osm file with raw OpenstreetMap data cannot be directly rendered by Osmdroid. Map tiles are usually rendered from that data in quite complex way and not on the fly.
Another very important feature in Osmdroid library is the ability to display so called Overlays. E.g. Markers, polygons etc. You may use those to draw your route on the map and other features you may wish to display. This is again covered in the documentation and too big to go in details here.
There is a support for routing for Osmdroid (AFAIK in Osmbonuspack) but that's about using some 3rd party service to get your routing data and displaying that. According to your comment you want to implement your own algorithm and therefore this would be no use to you.
So the last part is how to integrate your algorithm into that. That's not a simple question with a simple answer. You'll need to do almost everything on your own, starting with getting the data you need to run the algorithm from the OpenstreetMap database (.osm file). I don't think there's an API which would provide you reasonable way to access the data in a form suitable for route computation. The approach I would choose is to develop some kind of preprocessing which would take either .osm file or a database with the data an produce my own structure representing the graph for navigation. I would than include this graph in my application and run my algorithm on that data. The output of my algorithm would be the route: a list of coordinates which I would use to draw the polyline.
If the area you need to cover is small enough, you may start with including the .osm file in your project and running the algorithm in the same was as you do now. Maybe it's going to be good enough for your situation.
One interesting project to look at to find inspiration is Graphopper - they have build exactly what I said above and they use it to provide a library for Android/iOs and a web API. But the core is the same - pre-process OSM data into graph data and run the algorithm on that. Since you wish to implement the algorithm on your own this library will not help you (unless you fork the project and modify it) but it might be a valuable learning resource.

Offline map (.obf file) in android?

I want to include a MapView in my Application. I have been playing around with the Google Api a bit and it worked quite well.
But now I want to have a map completely offline. I know there are a lot of possibilities to do this.
The problem is that I have maps with .obf extension not zip. It should be possible to zoom in and out and to set markers at specific locations.
I know that there are things like Osmdroid. But I can't find any tutorial to load .obf file.
Thank you in advance.
I suggest you to have a look at OsmAnd.
It works with .obf format and provides you offline navigation.
OsmAnd

How do I add markers to streets only - Android Development

After plenty of searching, I haven't yet found a solution that works for me and I'm really hoping someone here could help me. First I'll explain my problem, and then I'll mention some of the approaches I've attempted/considered so far.
Basically, I'm developing an Android app where markers randomly appear around the user's location. The catch is, the markers need to be placed on streets only.
I've been working with Google Maps Android API V2 but I'm trying to work around using anything with "limitations" such as 'geocoding'.
I've considered using different map API's such as Nutiteq but I've had some trouble implementing them. It would be nice to stick to Google since I've become familiar with it but I'm willing to try any suggestions you may have.
I have even considered loading up Google Maps API V3 in an html file so that I can use GDirections to load a path from one point to itself and then parse this data to Google Maps Android API V2 using JS but turns out GDirections has a limit as well.
Anyone have any idea how I can go about doing this? Even if the solution is hacky, it's still something.
I'm fairly new to Android Development.
Funny what you want to achieve. You don't need to load API V3 html. You can use directions api directly: http://maps.googleapis.com/maps/api/directions/json?origin=51,19&destination=51,19&sensor=false
It still has limitations, but is was like 2000 or something a day a device. And you don't want to put more than 2000 markers on single user's screen, do you?
This is easy to parse, for example with Gson.

Alternative(To Google Maps) Open Source Map API that provides a database of nodes and Arcs on roads

I need a Map API for Android that can provide me with indexed nodes and indices that make up the road network. The main idea is to determine if two GPS devices are on the same road. Thank you in advance
A Map API by itself will not have that information. Anyway, you can get it from OpenStreetMap freely. You can download it from here.
I don't understand from your question if you intend on displaying the results on a map. If so, and you want a nice and free map API, I would suggest Leaflet. It's not as mature as the likes of OpenLayers but, as you've tagged this post with "android", Leaflet just kicks ass in the mobile department.
OpenStreetMap is definitely a good source of data for this kind of project. Unlike google maps, it gives developers access to the underlying vector data of a map (fully open). This allows interesting new use cases which simply are not possible with google maps, and something involving geometric calculations like this would definitely fit into that category. You either need OpenStreetMap or some other source of "vector" map data, and beyond OpenStreetMap this can be expensive.
Unfortunately that's not the full answer to your question. You still have a lot of work to do to use the data in the way you intend. You need to calculate the proximity of two points (GPS readings from two devices?) to nearby roads, and figure out which road the point lies closest to. It's the kind of powerful geo calculation you might do using a GIS package such as QGIS or a functions of a geo-aware database system PostGIS.
But that's not the answer to your question, because you need to do these calculations on device. I'm not aware of an off-the-shelf library to do this on android. I think you would have to roll your own.
But another challenge is to get the vector data onto the device in a suitable format in the first place, and this is the first thing to solve. You'd want the vector data either as a large download for a whole country, or perhaps a smaller area, perhaps with an on-the-fly download feature within this app. Whole countries are not infeasible when working with maps in vector form (ever tried the awesome MayDroyd app?), but require some compact formatting. Happily some of these problems are starting to be solved in open source off-the-shelf libraries. You could try to build on top of MapsForge for example.
So then you're back to the challenge of writing on-device code to poke around in this data and do the calculations you want to do. I suppose it could be rather good if projects like MapsForge included generic PostGIS style geo-functions to make this easier. Something to ask the mapsforge developers about perhaps.

Offline maps OSM

I am a bit stuck with an idea of offline maps in android application.
I want to use Open Street Maps. But how can I redesign their styles and then use in my project? By the way, the resource, I am looking for, has to be free..
Are there any good tutorials about this? I am new to this, so would be thankful for any helpful information.
Here are the basics:
Raster tiles are awful. To my mind, this approach of mobile mapping is very old-fashioned and has no advantages (unless your plan is to make a very bad-looking application).
The other thing is vector tiles. All the data is saved in much more efficient way and can be displayed very beautifully.
And the solutions (nominees) are:
Mapsforge - thanks to #dkiselev
OSMAnd app - thanks to #dkiselev
Mapbox GL (the android version has no releases now, but they are working really hard on it). If you really like mapbox, you can think about
Mapbox Android SDK, which uses raster tiles, but I believe, that
switching to Mapbox GL will not be that hard, when the GL lib will be released.
AirBNB AirMapView - open source and has release version
Urban Labs Sputnik Demo - also interesting solution, but I didn't use it.
Mapzen Open - open source android app, that uses all the best from everywhere. - winner!
And by the way, mapbox gl actully allows rendering your own mapping data (from your own provider). There is a closed issue on github about that, opened by me couple of days ago, and very good answer by one of the project developers.
If you don't care about using your own data source and want to rapidly implement custom (not google/apple) maps into your project - there are dozens of solutions for you as well. You could think of Mapbox, Scobbler, GetYourMap or, again, just google it to find more. There is actually a great article on OSM website about most popular libraries and apps for android ever developed.
Finally, I wish you good luck with your mapping project. And never forget:
if you can't find something doesn't mean it really doesn't exist
- probably you've just been searching not enough.
Offline raster tiles cache
If you need to show your map offline with custom style, you may use any kind of OSM renders. http://wiki.openstreetmap.org/wiki/Rendering
For the case of several cities, I would recommend you http://wiki.openstreetmap.org/wiki/AlaCarte or http://wiki.openstreetmap.org/wiki/TileMill
Create your own style, and export map tiles to sqlite db archive.
After that, you will need to create your own TileProvider for OSMDroid library. This answer could help you How to use MOBAC created OSMDroid SQLite tile source file offline?
Offline vector tiles.
Getyourmap
If you need more than just rendering with custom style, you may use:
https://getyourmap.com/ it's OSM vector renderer. But there would be some problems with accessing raw data to create routing and searching.
OSMAnd
And maybe the hardest but the best way, is to use OSMAnd. It's open-source, there are lots of capabilities, but it's an application, not a component or library.
So if you want to create a stand alone app. you will need to cut off features which you don't need.
Mapsforge
https://github.com/saintbyte/mapsforge It's opensource so it would be possible to add routing and searching. Style, as I know may be customized, but I haven't try it.

Categories

Resources