ANDROID APP
I've use google direction API to get a route from 2 points.
All the routes returned is saved if there is a need to reference to any of that data
Then I decoded the overview_polyline into a list of LatLng and drew the polyline on the google map.
How do I find out if a given coordinate (traffic accident for example) is on/nearby the polyline route , plus minus a constant distance (maybe 100m?)
You can use Google Maps Utility Library.
Especially isLocationOnPath(LatLng point, java.util.List<LatLng> polyline, boolean geodesic, double tolerance).
Here's the full documentation.
Related
This question already has an answer here:
Google Maps API and custom polyline route between Markers
(1 answer)
Closed 5 years ago.
Basically, what I simply need to achieve is, first draw the route between two points, from current location to any other point on the map. And when a third point is place, the route must change from current to third point and finally from third point to final point.
For reference,
Point A - Current/Start Location
Point B - End Location
Point C - Third Location
Tasks
1) Draw point from A to B
2) If C point is placed, draw from A to C and C to B.
How can I implement this ?
Thank you
you can use way points. When calculating routes using the Google Maps Directions API, you may also specify waypoints for driving, walking or bicycling directions. Waypoints are not available for transit directions. You can use waypoints to calculate routes through additional locations, in which case the returned route includes stopovers at each of the given waypoints.
For more details visit here
Sample url will be like follows
https://maps.googleapis.com/maps/api/directions/json?origin=Boston,MA&destination=Concord,MA&waypoints=Charlestown,MA|Lexington,MA&key=YOUR_API_KEY
This should work.
private void displayDirection(List<LatLng> poly){
PolylineOptions polylineOptions= new PolylineOptions();
polylineOptions.color(Color.RED);
for(int i=0; i<poly.size(); i++){
polylineOptions.width(8);
polylineOptions.add(poly.get(i));
}
mMap.addPolyline(polylineOptions);
}
I have calculated route for 10 waypoints. If i simply create new MapRoute it will draw full route from first to last waypoint. Is it possible to draw part of route, from first to second waypoint?
I use 3.4.0.165 HERE SDK version. I have found this answer, but it for previous version.
I have tried to draw only first subleg in this way:
int duration = route.getTta(Route.TrafficPenaltyMode.AVOID_LONG_TERM_CLOSURES, 0).getDuration();
RouteElements routeElementsFromDuration = route.getRouteElementsFromDuration(0, duration);
MapPolyline mapPolyline = new MapPolyline(routeElementsFromDuration.getGeometry());
map.addMapObject(mapPolyline);
But when map tilt enabled polyline drawn somewhere above roads, and if i change scale polyline change position relative to map tile objects.
Is there a reason you can't create a new route with your two waypoints? If you're using a stopover waypoint, you will be required to pass through the waypoint no matter what. Thus calculating the route between the first and second waypoint will provide you with the same route as the subset of the full route. If you're using a via waypoint, you can't count on drawing a subset of the route since it could change any minute given you are allowed to deviate away from the next waypoint at which point it will be ignored.
Currently it is not possible, workaround - calculate route between each point and draw required part.
Am adding markers in my android app, but I need to make one feature, if I add marker not on street, I need marker to be added on the nearest known street. Like in this example: Add marker to nearest known street, but I need to make it with android.
this is my marker coordinates:
MarkerOptions marker = new MarkerOptions().position(
markerLatLng = new LatLng(point.latitude, point.longitude)).title("my marker");
Now I need execute async task to send coordinates to google and retrieve nearest road coordinates.What url should I use for that?
Then am planning to add coordinates to arrayList:
locationArray.add(new LatLng(point.latitude, point.longitude));
And show marker on my map:
mGoogleMap.addMarker(marker);
I enabled in my API manager : Google Maps Directions API and Google Maps Roads API
The question is ,what URL in my AsynTask should I use to get nearest street coordinates?
Maybe I need to use this: https://maps.googleapis.com/maps/api/directions/output?parameters and add my marker coordinates to parameters?
You know how to use json i recommend the following:
https://maps.googleapis.com/maps/api/geocode/json?latlng=yourLat,yourLng
In the response you will have all information about that LatLng, nearest street and number, city, states, country and plenty more.
If your purpose is to snap the coordinate to the nearest road you should consider the Roads API that has a Nearest roads functionality.
Have a look at the documentation
https://developers.google.com/maps/documentation/roads/nearest
So the URL that you can use in the async task is something like https://roads.googleapis.com/v1/nearestRoads?parameters&key=YOUR_API_KEY
If your purpose is to find the nearest available street address the Reverse Geocoding is good for this as was suggested by Henrique.
My app gets updated GPS coordinates periodically which I show using a Marker on map. I need to move the marker to a new position if the new GPS coordinates are different then what Marker is currently showing.
The problem is that comparing Marker.getPosition() is more accurate while LatLang is not, hence sometimes even when they are the same, my logic says they are different.
How to solve this issue?
Please note that the same LatLang i assign to Marker.
You can consider that two LatLngs are virtually the same if the distance between them is less than a given tolerance.
You can use the SphericalUtil.computeDistanceBetween method from the Google Maps Android API Utility Library
float YOUR_TOLERANCE = 1; // 1 meter
if (SphericalUtil.computeDistanceBetween(pos, buslatLng) < YOUR_TOLERANCE) {
// Both locations are considered the same
}
Hi I am new to android development.
I am on college project its based on location which is need to find list of latitude and longitude in between two points.
Given Starting position is 12.990143,80.215784 and destination position is 12.992595,80.217618.
Over the past days i search the google, i found so many links to find distance between locations and mid point. I cant able to find solution for my problem.
Please suggest some solution for this problem. I am struggling over days to find solution for this.
Thanks in advance
You can use the SphericalUtil.interpolate method from the Google Maps API Utility Library.
For example you can find a LatLng that is at 1/5 of the distance between your starting position and your destination by doing
LatLng origin = new LatLng(12.990143,80.215784);
LatLng destination = new LatLng(12.992595,80.217618);
LatLng result = SphericalUtil.interpolate(origin, destination, 0.2);
You can use the google Directions api to obtain a full PolyLine of the path. You can objain a JSON object and parse it to obtain locations in the path.
http://maps.googleapis.com/maps/api/directions/json?origin=12.990143,80.215784&destination=12.992595,80.217618&mode=driving
This will return a full JSON result which contains everything you would need to find the whole route to all the points falling on it.
You can look more into it on:
https://developers.google.com/maps/documentation/directions/intro#Introduction