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).
Related
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).
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'm need to use GoogleMaps for an android app
I need to build an android app that sends request to GoogleMaps API and recive only the list of directions (Turn right in 400meters at the next..) without showing any map
How to I update the list by user movement ?
(You currently passed first turn, heading to second turn.. 800 meters to next turn.. 400 meters to next turn)
If in answer 2 I get only String with "Left,Right,North.." How do I get the turn angle ?
(45-125 will be right, 90 will be absolute right)
I would like to hear about how to optimize the update ( There are 4 ways to use threads in android so I've heard )
Listen for Location Updates using requestLocationUpdates().
http://developer.android.com/training/location/receive-location-updates.html#StartUpdates
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
I've got a series of Location / GeoPoint objects that form a polygon in my Android app. I wonder if there's any way to calculate the area covered by it.
So far I'm thinking about setting up a web service that, when posted the list of coordinates, uses the JS Google Maps API v3 to calculate the area. But there might be a way of doing this easily with some feature from Android I don't know about, natively.
Thanks in advance for your help!
A method doing this is posted in following answer:
https://stackoverflow.com/a/16210785/891479
This is based on following formula:
http://mathworld.wolfram.com/PolygonArea.html
http://en.wikipedia.org/wiki/Polygon
Principle of plolygon area calculation using this formula:
http://maruzar.blogspot.com/2011/12/irregular-and-regular-polygon-area-by.html
If you want to do it yourself, the way to calculate any polygn area knowing the corrdinates is explained in Polygon.
You can find a more comprehensive explanation in How to Calculate the Area of a Polygon under the topic Irregular Polygons
Just in case it helps someone, there is a very good answer in this thread:
Calculate the area of a polygon drawn on google maps in an Android application
The answer from Marian Paździoch:
There's already a library for that.
import com.google.maps.android.SphericalUtil;
//...
List<LatLng> latLngs = new ArrayList<>();
latLngs.add(new LatLng(51.893728, -8.491865));
latLngs.add(new LatLng(51.893550, -8.492479));
latLngs.add(new LatLng(51.893216, -8.492224));
latLngs.add(new LatLng(51.893404, -8.491598));
Log.i(TAG, "computeArea " + SphericalUtil.computeArea(latLngs));