itinero / routing

The routing core of itinero.
Apache License 2.0
221 stars 69 forks source link

Itinero Xamarin Android #190

Closed florinmarica closed 6 years ago

florinmarica commented 6 years ago

Hello! I'm trying to create a Xamarin Android app with offline map and routing using Osmsharp and Itinero. I have a lot of problems with the plugins, i don't know if i'm doing the right way but i can't find an complete example. My main 2 problems are:

  1. When I'm exploring the map some tiles dosen't load and i don't know how to debug this. 2.The route calculate method take a long time to execute for 2 point ( the coordinate for those 2 points are on the road).

Thanks!

xivk commented 6 years ago

There are two things you need to make sure you did on the mobile devices:

About the contraction there is more info here:

http://docs.itinero.tech/docs/itinero/basic-concepts/routerdb.html#contraction

About the no-cache thing, that's here:

http://docs.itinero.tech/docs/itinero/basic-concepts/routerdb.html#memory-mapped

About OsmSharp and it's UI, it's not supported anymore. We recommend you use Mapsui, it's way better and it's very actively maintained, it's the better choice :+1:

florinmarica commented 6 years ago

Thank you very much for the fast response. Now the route calculate very nice and fast. i will try the mapsui and see how it works. Thank you again!

florinmarica commented 6 years ago

I switched to Mapsui and when i deserialize the routerdb file it's throw this exception "Cannot deserialize routing db: Invalid version #: 9.". The routerdb was created from osm.pbf with winforms itinero.

xivk commented 6 years ago

Make sure you install the same packages... you can only use a router db in a later or equal Itinero version compared to the version it was created with.

florinmarica commented 6 years ago

Yes thank you, sorry for that, i use 14.0-pre53 for serialize. How can i add the route to mapsui map? i can't find anything.

xivk commented 6 years ago

There is no standard way but me and @pauldendulk have been discussing making a sample. I guess for now you have to convert the route object to a linestring and then you can add it to the map.

Correct me if I'm wrong @pauldendulk

pauldendulk commented 6 years ago

It has been on my todo list for far too long. Ben, could you give me a few pointers. What is the todo list. Add the itinero nuget package. A specific one? What data to use? Which commands will I need?

xivk commented 6 years ago

I think if we start with a sample on how to show a route on the map them we're fine for now.

Later I would move to using the routing data to also try to render a basemap or at least an overlay on detailed zoom levels.

pauldendulk commented 6 years ago

Ok. Let s do that. So which package do I use?

florinmarica commented 6 years ago

This is how i try to add the route to map, but i think i do something wrong because it doesn't show.
private ILayer LayerRouteW(Route route) { List p = new List(); foreach (Coordinate coordinate in route.Shape) { p.Add(new Point(coordinate.Latitude, coordinate.Longitude)); } LineString ls = new LineString(p); Feature f = new Feature { Geometry = ls, ["Name"] = "Line 1", Styles = new List { new VectorStyle { Line = new Pen(Color.Red, 8) } } }; return new MemoryLayer { Name = "Route", DataSource = new MemoryProvider(f), Style = null }; }

Edit: i find out that the Points need spherical coordinates and it works.

private ILayer LayerRouteW(Route route) { List p = new List(); foreach (Coordinate coordinate in route.Shape) { var spherical = SphericalMercator.FromLonLat(coordinate.Longitude, coordinate.Latitude); p.Add(new Point(spherical.X,spherical.Y)); } LineString ls = new LineString(p); Feature f = new Feature { Geometry = ls, ["Name"] = "Line 1", Styles = new List { new VectorStyle { Line = new Pen(Color.Blue, 6) } } }; return new MemoryLayer { Name = "Route", DataSource = new MemoryProvider(f), Style = null }; }

pauldendulk commented 6 years ago

@florinmarica What is this List p = new List();? Reminiscence.Collections? What does your using look like?

pauldendulk commented 6 years ago

I am trying to get started, help me out: https://github.com/Mapsui/Mapsui/blob/master/Samples/Mapsui.Samples.Common/Maps/ItineroRoutingSample.cs

florinmarica commented 6 years ago

i think the text was formated I'm using: List< Point > p = new List< Point >(); - Generic list

/* using Android.App; using Android.OS; using Android.Support.V7.App; using BruTile.MbTiles; using Itinero; using Itinero.LocalGeo; using Mapsui; using Mapsui.Geometries; using Mapsui.Layers; using Mapsui.Projection; using Mapsui.Providers; using Mapsui.Styles; using Mapsui.UI.Android; using SQLite;

*/

xivk commented 6 years ago

Don't use Reminiscense, that's just for Itinero use only... The code looks good, just add whatever is in the shape array to the map.

xivk commented 6 years ago

@pauldendulk Just installing the base Itinero package should be enough. If you want to load data from OSM in your sample all then also add Itinero.IO.Osm and you can load OSM data.

pauldendulk commented 6 years ago

@xivk @florinmarica My remark about reminiscense was just confusion that arose because something had gone wrong when pasting.

pauldendulk commented 6 years ago

@florinmarica If you use code then put it between back tics, these, top left keyboard: ` https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#code-and-syntax-highlighting

pauldendulk commented 6 years ago

@xivk Could I do routing without data?

pauldendulk commented 6 years ago

Now it compiles https://github.com/Mapsui/Mapsui/blob/master/Samples/Mapsui.Samples.Common/Maps/ItineroRoutingSample.cs

        private ILayer LayerRouteW(Route route)
        {
            List<Point> p = new List<Point>();
            foreach (Coordinate coordinate in route.Shape)
            {
                var spherical = SphericalMercator.FromLonLat(coordinate.Longitude, coordinate.Latitude);
                p.Add(new Point(spherical.X, spherical.Y));
            }
            LineString ls = new LineString(p);
            Feature f = new Feature
            {
                Geometry = ls,
                ["Name"] = "Line 1",
                Styles = new List<IStyle> { new VectorStyle { Line = new Pen(Color.Blue, 6) } }
            };
            return new MemoryLayer
            {
                Name = "Route",
                DataSource = new MemoryProvider(f),
                Style = null
            };
        }
xivk commented 6 years ago

Work is now ongoing in the Mapsui repo, getting back to this once 1.4 is released.

pauldendulk commented 6 years ago

ok