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
Related
I am developing an app which given a postal code will return map of the area with all the roads in the 100m radius highlighted either green red or yellow based on our machine learning algorithm. My task is 2-folded
Gather all the roads in 100m radius given Postal code
Highlight those roads using different colours
Our solution to the very first problem is quite inefficient atm, we are trying to convert the postal code to LatLng and then calculate boundary boxes with LatLng +/- 100m and extract street names. This sadly uses so much bandwidth AND API calls that we must look for a new solution. Is there anything we could use instead?
As of highlighting those roads that are another problem, as I have encountered problems where the application needs to highlight specific route, which was solved using polylines based off points google maps API returned. In this case, though, no points are returned as of now.
I know that those are 2 question but they are so closely related to each other (as the output of 1st problem will be used in the drawing lines) that I've decided to ask them together.
Really appreciate your help!
In case people are wondering how to solve similar question here's how we solved it:
Our current solution is sending the initial Postal Code and radius to OpenStreetMap API called overpass (http://wiki.openstreetmap.org/wiki/Overpass_API) which returns streets within given bounding box (which is calculated using postal code longitude and latitude) as a WAY (set of points in JSON format). The returned WAY can be easily visualised using polylines included in the google maps API.
Hope that helps!
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.
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.
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)
I want to draw route between 2 points in Google map with a pin mark at ends points. in this, user can choose any driving route like by car, by cycle, by walk. I have to show routing information like "2 miles ahead , left from next street" and also estimated time.so regarding this , I found a lot of tutorial on the internet. the best I found is:
http://code.google.com/p/j2memaprouteprovider/source/browse/#svn/trunk/J2MEMapRouteAndroidEx
which is very complex and slow.
next I found this one:
http://www.anddev.org/google_driving_directions_-_mapview_overlayed-t826.html
this one is very similar to what I want, except some feature. but it is outdated.
I also found that I have to use KML for this. but i don't want to use it because of complexity so is it necessary to use KML? is there any better way to do this? can i have full source code as I got confused by seeing chunk of code. thanks a lot in advance,.
rock,
The simplest solution for this is to open "Google Map Application" that is already installed in android device. Just pass the source and target location's latitude and longitude as a parameter and call the google map application as follows:
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?saddr="+latitude_source+","+longitude_source+"&daddr="+latitude_dest+","+longitude_dest));
startActivity(i);
Using this approach, you can also choose any driving route like by car, by cycle, by walk etc and other functionalities that is provided by application.
Google Directions API contains everything you need. I found it easier to learn how the service works before looking at any complete source code.
Basically you will have to execute a UrlConnection and read the input stream. If you paste a basic request into a browser, you can see how your input stream would look like. Ex:
http://maps.googleapis.com/maps/api/directions/xml?origin=Chicago,IL&destination=Los+Angeles,CA&waypoints=Joplin,MO|Oklahoma+City,OK&sensor=false
The result contains everything you would need but you will have to parse the result for information like step by step directions. Also the node called "overview_polyline" is what you would use to draw a complete route on the MapView. You could use the formula here to decode that polyline into a list of coordinates.