Trace the location only on Road in Google maps V2 android - android

I want to show the current location of the user only on road(not beside of the road) while moving. I have used the LocationManager to get the current location. But sometimes I am getting the location beside the road, with this, the location point on map is showing beside the road. Actually, I have to show his location on Road(if he is beside the road) only. I searched lot for this but didn't get any idea.
Example: How I am getting the current locations on map.
m
A---n-------B
here, A is start point
B is end point
n is on road(current location for sometime)
m is beside road(current location)
But I would need the m also should be on road.
Please help me on this..

The google directions service will calculate from nearest road so calculate directions from current location to current location - returned starting location will be on a road.
But what if user genuinely is off-road in a shopping mall carpark for instance?

For that you need to use road API which will give you the path upon the road otherwise you will not get the accurate path.
Snap to Roads
The Google Maps Roads API takes up to 100 GPS points collected along a route, and returns a similar set of data, with the points snapped to the most likely roads the vehicle was traveling along. Optionally, you can request that the points be interpolated, resulting in a path that smoothly follows the geometry of the road.
Check Details Here
You need to call like this
https://roads.googleapis.com/v1/snapToRoads?path=-35.27801,149.12958|-35.28032,149.12907|-35.28099,149.12929|-35.28144,149.12984|-35.28194,149.13003|-35.28282,149.12956|-35.28302,149.12881|-35.28473,149.12836&interpolate=true&key=YOUR_API_KEY

Related

How to update latitude/longitude in Android on google maps?

I am developing an indoor location application where the latitude/longitude will be updated from gathered sensor data. I cannot find any API that assists with simply updating the latitude/longitude on a map as that is literally the only thing I want to do. I do not want to use GPS data as the intent of the application is for indoor locations where GPS signal is heavily challenged i.e. under ground parking. Did I maybe miss something in the google maps API that someone can point me too? I will be calculating the new latitude/longitude using old lat/lon data and the sensor data (accelerometer for example).
So long story short, I want to update the marker on the map using sensor data only and I cannot find a library function in the API that allows me to update latitude/longitude on the map. Is there anything that can do that based on the new latitude/longitude I calculate?
You should save a reference (1) of the marker that you first create, and then update (2) his location.
1)
Marker marker = mMap.addMarker(new MarkerOptions().position(firstLatLng));
2)
marker.setPosition(newLatLng);
Actually, if you want to know more about updating all map features take a glance at google map API
But, if you are running out of time and want a quick fix to your lattitude and longitude updates every time then have a look at this receiving location updates

How to find the distance between two points along a specific route?

I'm developing an android app for my college that helps students track the current location of the college bus and also give them an estimated time when the bus might reach them. As of now I get the current location of the bus(via a device present on the bus) and the location of the student. I'm stuck at the point where I have to find the distance between the two GPS co-ordinates. I have to find the distance between the bus and the student "along a specific route" (i.e the path the bus takes). Using Google Map APIs will not always give the distance along the route I want. How do I find the distance between two points along a specific route?
The Google Maps Android API Utility Library has a range of applications useful for your case, including calculating distance between two points, by using the computeDistanceBetween(LatLng from, LatLng to) method from the SphericalUtil class.
Also check this link.
Google Distance Matrix API provides travel distance and time for a matrix of origins and destinations.
Or you could try Google Directions API.
Also, I believe this guy had the same doubt of yours.
Hope this helps you.
I would it solve this way:
1) The direct line of sight distance betweent two GPS points is simple, simply use Location.distanceBetween() method, you will find hundres of posts here on SO.
2) The length of the route.
This part is more difficult. If you are not happy with the result of google:
Store your bus routes as rough sequence of lat/lon coordinates (a poly line). A point per street corner should be sufficient.
Then find the nearest point on the route, a simple brute force search should be sufficent for your task.
Then simply iterate from found route point till destination point, and sum up using the distanceBetween() method.

Marking multiple different location in Map View?

I'm a newbie in android. All I can do is to put a marker in the user current location.
But what I need to do is put a marker in the user current location and to a specific places that near the user location. For an example a marker in the user and a marker in all the KFC that near the user location. But I don't have any idea yet how to make this work.
any thoughts will be accepted.
what you might need to do is an annotation, or itemizedOverlay. This is covered in Part 2 of this tutorial, which is step by step.
https://developers.google.com/maps/documentation/android/hello-mapview
Otherwise if you are just firing an intent to the map app. Then just sending the location of KFC would suffice since the user location will appear in the native app anyway
http://developer.android.com/guide/appendix/g-app-intents.html
geo:latitude,longitude
geo:latitude,longitude?z=zoom
geo:0,0?q=my+street+address
geo:0,0?q=business+near+city

Reverse Geocoding in Android : Error "IOException:Service not Available"

My app is totally based on maps. The requirement is user need to enter the source and destination in words then i need to draw the route on map with those values with markers. Later on the displayed map with route drawn, the user able to change/modify the source or destination by dragging the marker which are displayed. Simultaneously the route drawn should also change dynamically with user's action.
I can get the lat & long from the map using onTouchEvent. But in the same map not able to set both source and destination.
And i tried reverse geocoding to get the lat & lon from given location names. But i get IOException:Service not Available. I was searching for solution, then i found this link which started in jun 2010, still no fix for this bug till now.
Please help.Also provide sample code.
Thanks.

Get a list of nearest business

I am trying to use MapView and I want to show in the map some points of interest (like restaurants or stores) near my location. Is there a way in the api to get this kind of list? I know I can do this manually, but first I would need to get the geolocations. So which would be the best way to do this?
checking current location is possible. but we can get the center point of set of lat & lang. get nearest lat&lang from current location is the solution for now.

Categories

Resources