getting direction from latitude and longitude - java

I have calculated the distance between two latitude and longitudes using the Haversine formula,but how can I know the direction to which I should move.
for example : the distance of a hotel is 10 m from my location but i don't know which direction it is.
Hope it makes sense.

If I haven't misunderstood, you should use the bearing. It refers always to north

Related

Finding geopoints within radius in Java

There is geopoint array, one point with longitude and latitude as the center and radius. It takes to choose only those ones which are within the radius. One more thing is that the points are close to prime meridian. Can you advise the solution for it or some java libraries?

Calculate path and distance between points

I'm writing application in Java. I have a list of lat long, and I want to convert it to path. Then calculate distance between points. And finally base on current location (lat, long) detect point on path, and calculate remaining distance to final point.
How can I do it, do you know any libraries that could help me?
When the points are not that far apart you can calculate the distance using the Pythagorean theorem. By calculating the distance between the points and adding them up you can get the total distance. (I assume that the points are sorted) I believe you also want to get the point on the path that is the closest to the current location. To do this you can use the same formular to check the distance for every point and use the shortest. If you have really many points you might want to use only every 10th point first to save time and resources.
I hope I could help you

How do I figure out longitude and latitude coordinates to create a 1 mile radius around a user's location?

How do I figure out longitude and latitude coordinates to create a 1 mile radius around the user's location? I don't mind how many coordinates there it takes, but I'd like to create a circular radius around one location.
For instance:
If the user's location is =
Latitude: 44.947 Longitude: -93.098
How do I then figure out what 8 sets of longitude and latitude coordinates create a 1 mile radius around the above location.
(8 in the above example is italicized as I don't mind if it's less or more than 8)
How do I do this?
Code so far:
LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
double longitude = location.getLongitude();
double latitude = location.getLatitude();
Does anyone have any ideas?
Although I am pleased people are trying to help, the answers given below, don't answer this question.
Bearing in mind that I'm not experienced in Android so if this doesn't apply ignore me.
With the web version, the easiest way to achieve what you're looking for is to use the drawing API to create a circle of the radius you're looking for (in this case a mile) centered on your users location. You can then use the built in methods to find the corner bounds points of this object (unfortunately rectangular) to give you the long/lats you're looking for.
If you want to create a circle on map then do this:
1) Get a refference to your map fragment :
GoogleMap = MyMap;
MyMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map_id)).getMap();
2) Draw the circle:
MyMap.addCircle(new CircleOptions().center(new LatLng(latitude,longitude)).radius(0.00062).fillColor(0x88000000).strokeColor(0x44000000).strokeWidth(2));
1 meter = 0.000621371 miles
If you don't know how to use Google Maps API v2 then follow this link

Geometry.getarea() and Polygon.getarea() what are the units?

So I am working with a set of images where the the corners are the lat long on the map. I am creating Polygons to check if there is overlap of the given images. I need to know the units associated with the .getarea() methods for both Polygon and geometry. I'm using the following objects to create my polygons and geometry
http://tsusiatsoftware.net/jts/javadoc/com/vividsolutions/jts/geom/Geometry.html#getArea()
http://www.vividsolutions.com/jts/javadoc/com/vividsolutions/jts/geom/Polygon.html
When using both of the above objects I get a number back however I have found no indication on what the units associated with the number are. So are we talking meters, kilometers, miles?
a sample of cordinates i'm using are
+30.658739 -086.345670, +30.659997 -086.34002, +30.664041 -086.345082, +30.662783 -086.342750 I'm looking for the area between these 4 points.
the value i get back from the .getArea() is 1.31039680000139E-5 The points are realitively close so i'm thinking its in meters which would be 1310.4 meters
This is difficult to tell without knowing what the underlying coordinate system is. After taking a quick glance at the Javadoc API you linked to, I suspect that your geometry package is probably dealing in raw cartesian coordinates and is agnostic about the units of measurement being used. If this is the case, you are on a very slippery slope. Here's the problem:
Not All Degrees Are Created Equal
Degrees in latitude all have the same spatial resolution. Each degree of latitude corresponds to roughly 111km of distance. This is not the case for degrees of longitude. At the equator, degrees of longitude correspond to 111km of distance, but at the poles, 1 degree of longitude has ZERO km of distance. In other words, if you have a Lat/Lon box with the upper left at 10:0 and lower-right at 0:10, it will have more surface area than a Lat/Lon box with upper left at 20:0 and lower-right at 10:10, even though the sides of those boxes are all 10 degrees long.
A second issue is the curvature of the earth. Because of the earth's curvature, a 100km by 100km square on the earth's surface will have more surface area than 10000 km^2, because the shortest distance from one point on the earth's surface to another is not actually straight line, but an arc.
A third and often-overlooked but less-important issue is that the Earth is not actually a sphere, but an ellipsoid. It tends to bulge near the equator, which breaks our assumption that a degree of latitude anywhere on earth is the same distance as another degree of latitude anywhere else. However, this issue does not introduce as much error into our surface area estimates as the first two.
In other words, spherical (or in reality, ellipsoidal) surface area isn't an easy problem to solve, at least not as easy as mapping to cartesian coordinates and using them to find euclidean measurements of surface area. You can get away with it if the surface area you are dealing with spans a very small angular distance, but the larger your lat/lon box is, the more distortion you get.
Possible Solution
This only works if your images are rectangular and top/bottom of the image have constant latitude from left-to right. This still introduces more error with wider ranges of latitude because it still ignores the curvature of the earth, but does a better job than assuming all degrees are created equal in a cartesian coordinate system. If this is the case, then the intersection of your image will be bounded by the following coordinates:
topLat:*leftLon*, bottomLat:*rightLon*
Calculate the average latitude, then use it to find distance per degree of longitude at that average latitude, kmPerLon. We now have the following equation:
area = ((topLat - bottomLat) * 111km) * (rightLon - leftLon) * kmPerLon)
The area you get from this will be measured in square kilometers, but again, I'd like to reiterate that this only works reasonably well if your images are rectangularly aligned to parallel latitudes and do not span much angular distance.
CodeBlind is correct that the library is unit-agnostic. The units aren't in the Javadoc because JTS has no opinion on the subject. You can use whatever units you want. If your units are inches, area will be in square inches. If you're using feet, area will be in square feet... and so on. If your numbers are in degrees, then your area is in degrees squared.
What are the distance units in com.vividsolutions.jts.geom.Geometry class?
From that post Distance is in radian (and I have proven it). Then I wonder if the area is also in radian. So I tried it with this:
Math.toRadians(polygon1.getArea()) * 6371000 * 100 => this one become square kilometers.
I don't know if this is accurate or not. But it came pretty close

measure area of irregular polygon in android

I am developing one application in which i have draw the polygon on map and map that I have used is not google,Its Mapsforge opensource offline map library.i have easily draw polygon on map by converting geopoint into pixcel point.but here i want to find are of that irregular polygon,and for that i have make lots of try but its getting me unsuccess..
I have tried with calculate area with basic Math but its not working in this case be case pixcel are change accodingly while change zoom level.
Here is Math logic :
Math calculation
for(int miAreainc = 0;miAreainc < x.length-1; miAreainc++)
{
sumX += x[miAreainc] * y[miAreainc + 1];
sumY += y[miAreainc] * x[miAreainc + 1];
}
int unit = ((sumX - (sumY)) / 2);
AppLog.showLogE(TAG,"UNIT >> " + unit);
I found that funcation stay at server side which get area from geopoint array,but here I want to make it offline.
I have tried so far but not getting any clue or result ..
Please help me out this..
Thanks
Note: I don't really know how stupid my answer is. So please let me know if it doesn't make sense and I'll delete it.
Since the map is not in Cartesian Coordinate System, your calculation will not yield accurate result. You need Spherical Trigonometry for Spherical Polygon which is not trivial.
There is a good discussion at Calculating area enclosed by arbitrary polygon on Earth's surface. Take a look.
But apart from all of these, I have found Projection.java in mapsforge which has a method to find the absolute pixel coordinates on the world map from GeoPoint at a specific zoom level:
Translates the given {#link GeoPoint} to absolute pixel coordinates on
the world map.
Point toPoint(GeoPoint in, Point out, byte zoomLevel);
I'm not really knowledgeable, but I think it will give you the absolute coordinate of GeoPoint on a projected map so you can use Cartesian calculation.
for area calculation you Need to transform lat, lon to cartesian coordinates with Unit Meters. (Not Pixels) Look into transform Moduls

Categories