Google maps api v2 how to find the nearest location - android

I am using Google maps api v2 in android. I have created xml parser for the bus stop. Bus stops are displayed using markers. I need to find the user's current location and find the nearest location (bus stop), best automatically (for example in a radius of 0.5 kilometer).
I tried to find a tutorial, but unfortunately I failed it.
Thank you for your help.

There is the distanceTo() method of Location class that gets the distance between 2 locations, in a straight line. You can find an example on how to use this here: How to get straight distance between two location in android?
But, if you don't want the straight line distance, rather the Travel distance, I'd recommend you take a look at this question and answer: Get the distance between two locations in android?

Related

Directions API for Android with traveling time

On our website we we plot two points on a map, and the google direction api neatly gives us the traveling time. If we change the from or to address some new calculation are performed, and the new traveling time is displayed on the site.
We are trying to create the same kind of setup in Android, but I see that there is no support for the directions API. I have looked at some old examples like this one Drawing a line/path on Google Maps but here there is just a simple line between two points. I do not see anything about the traveling times.
Another question I stumbled uppon was the following Directions API on Android but I do not see how the connection is made between the Android Maps API and the Google maps direction API.
To draw path you can use this library
Through this library you can get travel duration between two point. now when you move to your destination location you have to calculate your speed and remaining destination distance. from your speed you can assume you destination reach time.
To calculate your moving speed this link will help you

Android Google map get shortest path distance between 5 locations from the current location?

I want find the shortest path/route between multiple locations available.
i.e. suppose I have five locations A,B,C,D and E, I want to find the nearest location (using route distance not normal distance).
Currently I am making 5 URL and calling Google Direction API for result and comparing them. But it's long and time consuming process. Is there any alternative?
I also thought of using distanceTo() and distanceBetween() method but i think it doesn't show the route distance.
Any suggestions please....
Thanks

How to return a radius/key-word search of my data using Google Maps Android API v2

I am building a Android app using the Google Maps Android API v2.
I have a database of lat/long that Im trying to search and display, either by radius(in miles) and/or key-word based on my current location.
What would be the best way to approach this problem?
Thank you in advance.
How I would approach it:
Get the users location in lat/long
User the haversine formula to compute the distance to points already
in your database.
Filter out the points that meet your threshold criterea (less than 5
miles for example)
Within the GoogleMaps class, look at the addMarker() method. Use
this to add your filtered database lat/long to the map.
A similar approach with keywords, you filter by keyword and not haversine distance.

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.

Get Directions Google maps Android

There is a Google map and on it marked objects. With GPS defining man's place on the map.
The aim is to set the phone automatically detects and plot a route to the nearest object. How can it be obtained?
I find this tutorial very helpful:
http://www.anddev.org/google_driving_directions_-_mapview_overlayed-t826.html

Categories

Resources