Google Maps Android API v2 - android

There are two coordinate points which are marked on the map. What code should write whatever between these points traced the route as a line, but not directly, but on the roads, without specifying their crotch points?

Step #1: Find some Web service that will give you intermediate points, of sufficient granularity, along the desired route between the two end points. I have no idea if such a Web service exists that is publicly available.
Step #2: Use a Polyline to connect the intermediate points.
If by "without specifying their crotch points" you mean you do not want to use these intermediate points along your roads, please build a city that has perfectly straight roads, then limit your maps to that city.

Related

What libraries to use for Android Project with maps and routing?

Alongside with my friends I am about to develop an android application. The application will use maps a lot, finding routes, placing markers, drawing predefined routes, stuff like that.
There is this Google Maps APIv2. So I tried it, write some code and looks good. I am able to place markers and draw polylines, however my application will have some predefined routes. One route is set of LatLng points. So I just add these points to PolylineOptions and add it to map. Great, it works.
But these predefined routes will be created in web-based application also using Google Maps APIv2 or similar api/library. Some streets are not straight they are curved so you need to create a lot of LatLng points to get it look nice which is very important. I can do this but I want to put only two LatLng points - at the beginning of the street and at the end.
Here is the image:
On the left, route has only two LatLng points (red dots) and that is desired shape of line. On the right same route with 2 LatLng points gives me route coloured in light blue, and this is what actually happens if I just add polyline to GoogleMap object. In order to create same effect as in left image, I need to create many LatLng (red dots) points which is not appropriate for those who will create these routes. So this leads us to routing problem which can be solved by using Google Directions API. Which solves the problem of drawing routes with less markers. Basically what I understood, this API for directions actually creates a lot of these LatLng points that I draw using for-each loop as seen on right part of picture above. And I need to contact Google Web Service for this so I need to have Internet connection - and this is the problem.
Sometimes internet will not be available hence I need some alternative solution. I've heard of Open Street Maps, but I am not sure how to use it and does it needs internet connection for creating these routes.
Is there any free library that offers offline routing and showing maps offline? Basically all map interactions must be done without use of internet.
But it is understandable if internet connection is needed only for the first run of application as it is needed for Google Maps APIv2, well application crashes until I turn on internet, after which any next run I do not need internet..
A web based application will be made for creating these routes and routes will be created by users for whom we develop this application. And as users can be very annoying they will demand some user-friendly and easy interface for creating routes. Telling them that they need to create 100 to 500 points for each route, and if there is 60-70 routes they will gladly say NO to our application.
Any advice? If it is possible, I can write my own routing algorithm for Google Maps to work offline, I am very skilful at "Algorithms and Data Structures" - any guides/tutorials for this? But I guess this map is just set of tiles, and does not have necessary information for finding route.... So please correct If I am mistaken for anything.
You can use the Scout SDK (provides a free usage quota) as it offers full offline maps, routing & navigation.
Have a look into the open source projects GraphHopper, Mapsforge and OpenScience-VTM which can do routing and/or maps offline. And all use OpenStreetMap data. Other projects exists of course, have a look here and here.
Also have a look into the GraphHopper map matching component which could be interesting for your specific use case and can work offline too.
(Note I'm the author of GraphHopper)
If it is possible, I can write my own routing algorithm for Google Maps to work offline
No you can't, the data is not open nor you can buy the data to my knowledge.
Another option is OsmAnd. The OSM wiki also has some information about OsmAnd and even more information about OSM on Android in general as well as pages about rendering and routing.

Google Directions Service: consider each corner as a step

I'm working in an Android application that will use Google directions service.
The source location is determined by the GPS and the destination is set by the user, the user can also set some waypoints by touching in the MapView (this is optional). Finally the app draws the route between these points.
When invoking the Google directions service I get a list of "steps", as far as I'm concerned each step corresponds to a point where the driver has to turn (right?). Is it posible to get more steps? For example consider each corner of the path as a step?
Thanks in advance.
Finally I could draw a precise route by decoding the "polyline" of each step returned by the service. A polyline contains an object holding an array of encoded points that represents an approximate path.
So I decoded that into a List of GeoPoints and then drew the lines between those GeoPoints.
In case someone needs to do something similar, this was really useful to me:
Google Maps API Version difference

Google Maps Android API v2 routes json parsing

Hi With the help of LocationManager I managed to find current location in android.
For showing routes between two geo- co-ordinates what should I use so that I wont plot air distance instead will show ground routes or is it with help of json can I plot routes.
I have tried polyLine() but it gives straight line.
To work out the line between two points you need to know what map projection type you are using. Some map projections preserve shape (and therefore angles) others do not. Take a look at http://www.progonos.com/furuti/MapProj/Dither/CartProp/ShapePres/shapePres.html it might help.
If you're using a Mercator projection then I found this page that claims an algorithm in C# that should point you on your way: http://conceptdev.blogspot.co.uk/2009/01/great-circles.html
As for the line segments, ployline will give stright lines between the points. You'll need to use Path and use the Bézier curve methods Path.cubicTo() and Path.rCubicTo() from memory.
Do you have all permission set in the Manifest? Also, you have to enable the location service (is the gps icon in the status bar showing?). It'll take some time for the device to get the location, so see if onLocationChanged is called.
Here you can find the answer for your qustion:
Is there a way to show road directions in Google Map API v2?
and here:
Get driving directions using Google Maps API v2
basically what you should do is make a call to Google Directions API receive the road direction coordinates (many Latlng points), and then draw a polyline between each one of them.

Is it possible to get the route network from Android Google Map?

I am trying to find a way to get the map of the road network currently visible on the the screen, while using the Google Maps API v2 for Android. I want to place some markers along roads, but I don't know if that is even possible? I can get the addresses, or the path between two addresses(using the route manager), but I need to know if I can paths of...all the roads visible?
That want you want, is to get the route as vectors (as poly line of latitude, longitude) coordinates.
But, No you can't. (although there is an inofficial Google API that gest the route as coded and compressed vector, but the usage is not legal.)
The vectors are "owned" by TeleAtlas/TomTom and they are not public availble, nor has Google the right to give them out.
If you need vectors, then you have to use OpenStreetMap routing Service, which potentzally provides vectors of a route (via an OpenStreetmap API)

Display route in android

I am using following example source code but I can't get long distance route in map. It only works for small distance on map.
Is there are any limitation to access map?
If some one has better idea please help.
Here is a complete source code at https://github.com/frogermcs/RoutePathExample for how to draw path between two geolocation. I use this code without any trouble at all. You should check it
Make use of this secret Google API and Android Map API to show the distance between two points.
I am using this code and it is working fine, even if I put two points in two different countries. I believe you are not implementing it in the right way, because this code is retrieving the KML provided by Google for the two points you choose, which always returns a route unless the two points are in different continents and there is no route for going by car.
I suggest you show us how did you use the code in your app.

Categories

Resources