I'm developing an app in android using Google Map, I want to check if a marker is in direction from A to B or not ?
You can use the SphericalUtil.isLocationOnPath method from the Google Maps API Utility Library that, according to the Javadoc:
Computes whether the given point lies on or near a polyline, within a specified
tolerance in meters. The polyline is composed of great circle segments if geodesic
is true, and of Rhumb segments otherwise. The polyline is not closed -- the closing
segment between the first point and the last point is not included.
Related
Im trying to design a navigation app based on Google maps.
What I'm looking for is an article or any possible solution to let me be able to, given a polyline, which represents a route on the map, detect all interceptions between the polyline and markers on the map so that I can display for a distinct route how many and what kind of markers this route passes through.
Basically what I lm asking is if there is a way I can detect interceptions between my polyline(which represents a route) and the markers (which represent points of interest on the map, I e),
I've thought about using geofences but I can't find a method or a way that would allow me to get interceptions between polyline and geofences created over the markers, any kind of help would be appreciated.
Seems there is no specific method in Google Maps API, but if You have polyline points and marker coordinates, You can test for each marker and each polyline segment for marker on the polyline segment laying, for example by this way described by MrROY.
Update
You also can use PolyUtil.isLocationOnPath(LatLng point, java.util.List<LatLng> polyline, boolean geodesic, double tolerance) method form Google Maps Android API Utility Library to test intersection of Marker and polyline with tolerance precision.
i am getting a fully loaded map in my android app, and i am getting some directions waypoint using the directions API. What i would like to accomplish now is check if the desired route form A to B intersects with another polyline.
Can someone shed some light into this?
Thank you very much, cheers!
Loop for each straight line in first polyline
Loop for each straight line in second polyline
Test if both straight lines intersect. They both intersects if there exists one point that both line share.
Line equation if endpoints are known:
I have over 200 polygons to create and I get the location by LocationListenerOnChanged() but I would like to know which polygon I am in based on the current location .
How will I use LatLng to check within within each polygon every 2 miles.And how can I make the entire process faster or will android os has inbuilt function.
I checked a lot of documents related android maps v2 but I did not get any info about it.I appreciate any help w.r.t the topic .Thanks in advance.
There is no direct method in android api v2 to know if a latlng lies within a polygon. So you need to do a mathemetical calculation known as point inside polygon check. You can check out the below two methods suggested in earlier posts:
1, Raycasting method
2, Winding number method
If in your case, checking a point against all 200 or more polygons is slowing your app, you can consider reducing the number of polygons to be checked. First of all , for each polygon, other than their vertices, also store an approximate geometric center. Then when you get a new location for checking, find the distance between this location and the geometric center of all the polygons. Now take only few polygons ( say 8) whose centers are closest to the point and then do any of the above point inside polygon check for those chosen polygons.
I am currently developing an application that tracks your path, so it always draws on the map. I want to know if it is possible to draw on the road, since my application gets my location and its not precise, its always near(about 30 m radius) me. I want it not to add it where it is, but on the nearest road
You can draw the path on the map using the Ployline class of Google Map as below:
Polyline line=myMap.addPolyline(new PolylineOptions().add(new LatLng(location.getLatitude(),location.getLongitude())).color(Color.RED));
For more details about it please refer here
I have a list of start point and end point coordinates for zoned roads. When I put the coordinates in to google maps it shows the road correctly. I want to develop an android application that will alert me if I am on a zoned road.
How can I check if my current location is in the zone if I have only the start point and end point? can I use the navigation in some way?
If you want to see if a point is between two other points, the first solution that crossed my mind is as follows:
Imagine you have a triangle (point of interest, and the two end points ). If the hypotenuse is represented by the two end points, you can get the two angles that it makes with your point of interest. If both of the angles are <= 90 degrees, then the point is between them, if otherwise, it is not.
Hope this is clear.