I am currently porting the ios map app to android.
GMSGeometryIsLocationOnPathTolerance api I can't find what the corresponding android api is.
You need PolyUtil.isLocationOnPath() from Maps SDK for Android Utility Library:
public static boolean isLocationOnPath(LatLng point,
java.util.List<LatLng> polyline,
boolean geodesic,
double tolerance)
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.
Maps SDK for Android Utility Setup steps described here.
You can use it this way:
...
for (LatLng point : redPolyline.getPoints()) {
if (PolyUtil.isLocationOnPath(point, path.getPoints(), true, 50)) {
// point is on path
...
}
}
where 50 - is tolerance (in meters).
Related
is it possible to follow a path on google map android (Programmatically) if my android device getting away from the path it notify or show alert that your not following your path
Help will be appriciated,
Thank's :)
Yes, it's possible by several ways. For example you can use PolyUtil.isLocationOnPath(LatLng point, java.util.List<LatLng> polyline, boolean geodesic, double tolerance) from Google Maps Android API Utility Library. In this case you need to check (with isLocationOnPath()) if user location laying on segment of the polyline of your path. Something like that:
if (!PolyUtil.isLocationOnPath(userLocationPoint, pathPolyline.getPoints(), true, 50)) {
// user away of pathPolyline more than 50 meters
// show your alert here
...
}
}
where 50 - is tolerance (in meters).
NB! It's not a complete solution - just approach.
Also you can use geofence monitoring for several waypoints (with a limit of 100 per device user).
As the title states I want to know how can I find Intersecting point of two different routes in google maps API.
please view this image for better visualisation:
You can use, for example, PolyUtil.isLocationOnPath(LatLng point, java.util.List<LatLng> polyline, boolean geodesic, double tolerance) from Google Maps Android API Utility Library. In this case you need to iterate over each point of the "red" polyline and check (with isLocationOnPath()) if it intersects (lays on) each segment of the "blue" polyline. Something like that:
for (LatLng point : redPolyline.getPoints()) {
if (PolyUtil.isLocationOnPath(point, bluePolyline.getPoints(), true, 50)) {
// now "point" - is your target point
pointWhatYouWantToGet = point;
...
}
}
where 50 - is tolerance (in meters).
If you need polylines segments intersection, take a look at this answer of antonio.
I have an application with a map Activity. I also have put some markers on it.
I have found in this SO question how to draw a path between 2 points:
Answer : Draw path between two points using Google Maps Android API v2
How can i show only those of my markers that are close to this path in a radius for example 500m ?
You can use the PolyUtil.isLocationOnPath method from the Google Maps Android API Utility Library:
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.
public static boolean isLocationOnPath(LatLng point, List<LatLng> polyline, boolean geodesic, double tolerance)
You will need to iterate over your markers and make them visible or invisible depending on the returned value of PolyUtil.isLocationOnPath with your desired tolerance (500 in your example):
for(Marker marker : markers) {
if (PolyUtil.isLocationOnPath(marker.getPosition(), yourRoutePath, false, 500)) {
marker.setVisible(true);
} else {
marker.setVisible(false);
}
}
Hypothetical question. I'm building an augmented reality app using Google Maps API for Android. I'm wondering if there's any data that I can use to determine whether a building lies between me and a specified location. I ask this because when sufficiently zoomed-in, there is clearly 3D data on the shape of buildings included on the map. I was wondering if there was a method like:
boolean buildingInTheWay(myLocation, destinationLocation);
if (buildingInTheWay) {
//Do something
} else {
//Do something else
}
Perhaps there's also something that could be done where if the route to a location is much longer than the birds-eye path to a location, there must be an obstacle in the way (imagine two parallel streets like so:
- = street
X = buildings
A = start location
B = destination location
---------C----A-------
xxxxxxxx | xxxxxxxxx
---------D----B-------
Here, A to B would return true, as the route around the buildings is a lot longer than the direct distance. But C to D would return false, as the route following a road is almost exactly the same distance.
However, that's not very accurate - what about between buildings? I wonder if each building on Google Maps has lat/lng points for each of its corners?
Any thoughts, anyone?
I am working on custom map app and i want to use google map tiles for background ? There is one class TileProvider in api but i don't know how to initialize it every time i try it goes something like this ?
TileProvider tileProvider=new TileProvider() {
#Override
public Tile getTile(int i, int i2, int i3) {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
};
how to override getTile function to get tiles from google map server?
Any example will be appreciated ?I know getTile function need x,y and zoom value to return tile.
So quick answer is that you can get the Google Map tiles from the following URL:
http://mt1.google.com/vt/lyrs={t}&x={x}&y={y}&z={z}
Where {t} is the type of map (satellite, road, hybrid, etc) and the other attributes are specifying the coordinates and zoom level.
The possible values for {t} are as follows:
Default - m
Roads only - h
Roads simplified - r
Satellite - s
Satellite hybrid - y
Terrain - t
Terrain hybrid - p
That being said you do want to make sure what you're doing is NOT a violation of the terms & services. Specifically Google WILL allow you to cache their tiles provided that you are doing so ONLY in order to improve performance and that you delete their tiles at least every 30 days, and finally you don't pull down their tiles in an attempt to make your own mapping service.
You may want to read the Google Maps Terms of Service - https://developers.google.com/maps/terms - specifically section 10.1.1