You must use the city map offline, without an internet connection. The card must be stored in the phone's memory.

Maps can be static, not scaling the main conditions so that it is possible to draw on the map the lines seen from graphic coordinates of the type ( 65.249877 , 55.463608 ). That is, the scale of the map was taken into account.

As I understand it, Google does not allow you to use their maps without connection to the Internet.

On it I look aside OpenStreetMap. For this service I found more than the libraries described in this article.

I am interested in the experience of other people who have already tried to work in this direction.

What to use?

  • Try using Mapbox, as far as I know, they support caching - timuruktus

1 answer 1

Hi, I am an experienced person in this direction. At one time, I made maps based on the “megapixel” format, also known as the “Polish” format. This is a fairly simple format for understanding and there are converters from the OSM in it, but it is not very convenient to render it, just like the bare OSM itself (OSM is actually much more complicated).

First, you define a couple of functions: the transformation of latitude / longitude into screen pixels and back. Somewhere here you can use formulas for various projections, for example, often choose the Mercator projection. If the projection or the task allows, then all coordinates can be transformed into screen coordinates at once - it will be faster and more convenient to work.

Then you take points from your map, transform it into screen coordinates, and if it is on the screen, you draw on the canvas / scene that you have there. If behind the screen - it is better not to draw. To make it work faster, you make an index based on p-three or quad-three.

Drawing lines and polygons follows the same principle, but there is a nuance: a line, and even more so a polygon must be drawn even if it goes beyond the boundaries of the screen. Therefore, it is wiser to first break the map into small areas, with polygon recalculation. Roughly speaking, if we have a huge lake, then after splitting it will become a bunch of small rectangles with simple polygons along the edges, which can be rendered easier and in case of going beyond the screen boundaries, the losses will be minimal.

Polygons can be pre-packaged in a fan or snake sequence, which may give a little advantage when working with some hardware, but nowadays, I think, it does not have a big role. This I used to pick out performance like that.

Well, in general, all that is necessary is already there. It remains to write the indexer, which will lay out the cut lines and polygons in different areas, some kind of optimizer, so that at different scales the points merging into a single whole thinned out, and the benchmark will not get tired of it yet. Work with the profiler continues until there are more or less smooth animations or it does not get bored.

Add inscriptions on top (it is more convenient to store them in a separate layer), some icons, markers, and so on, and if we draw all this in full screen, above all we draw our own goo. Everything, the application works, there is a map, we are not dependent on anyone.

  • Thanks for the detailed description, the way to solve the problem, you are a very knowledgeable person. I would like to hear opinions from you on several issues. Why should I use the "Polish" format (please give a link to the descriptions of this format) As I understand it, I will have to create coordinate transformation functions myself? Is there a finished library where the tasks are already solved? What is bad OSM format? I'm picking up this library at the moment. Can you comment on this? - 112Legion
  • It is better not to use the Polish format, it was just already and it is easy to understand. The description is easily searched in Google. Transformation functions can be found in Wikipedia, and ready code to steal from any library that works with projections. In general, you can immediately put all the coordinates in Mercator and imagine that you work with pixels and just a very large picture - complete freedom. Libraries are ready to solve the sea, but I am not a monkey, which I urgently need to submit a project, but a programmer and I prefer to solve the problems myself, being responsible for. The OSM format is just great, but it's difficult to render it, try it and find out. - bukkojot
  • Sorry for the intrusiveness, could you clarify what you mean by "OSM - render it harder"? - 112Legion
  • Of course I will clarify. If you need to draw a road or a house, then simply take the data polylines or polygons and render the line or polygon. Everything. In OSM a little bit wrong. Firstly, there are many formats in which its data are presented, both binary and text, like XML. Secondly, if we find these roads, then instead of coordinates with latitude / longitude, we will get only a list of identifiers that we will have to find later separately to find out these coordinates. If we want to render polygons - we need to find all the relationships. In general, this is more correct, but rendering is more difficult. - bukkojot