Android position, Longitude (min, max), Latitude (min, max) - android

I have a little problem using Android.
I have my GPS position, clearly latitude and longitude, and a ray of search in meters (for example 100 meters), ok?
Imagin my position at center of the circle made by ray, I would know how to obtain on Android the:
topLeft Latitude
topLeft Longitude
bottomLeft Latitude
bottomLeft Longitude
of the rectangle that inscribes the circle.
Thank's in advance.

1) Convert center lat long to cartesisan x,y in meters:
(lat lon are on a sphere, x,y is a flat map then you can continue with school mathematics
2) use polar coordinates formula to create the 4 corner points
the first corner has angle 45 degrees, and r = 100m
second corner of the square has angle 45 + 90 degrees
3) convert back the 4 cartesian meter coordinates to lat,lon
a bit more detailed here
How to find a set of lat/long pairs surrounding a 5 miles radius of a certain location
and see my answer here
PHP: How to create a Geo-Fence(bounding Box) using the Distance from a set of Coords

Related

How to get the accuracy distance in GoogleMaps Api for Android

I'm trying to detect the coordinates of some markers based on current location, but my problem is, sometimes, the accuracy range circle of my current position is relatively large and i have very difficulty to detect those markers because my current location is a little far from the markers. My question is if there is someway to check if the coordinates of those markers are inside the accuracy circle of my current position, or to get the radius distance of the circle?
Accuracy parameter is precisely the radius of a confidence circle. From Android doc:
We define accuracy as the radius of 68% confidence. In other words, if
you draw a circle centered at this location's latitude and longitude,
and with a radius equal to the accuracy, then there is a 68%
probability that the true location is inside the circle.
You can also get distance between two GoogleMap Point doing this:
Location location1 = new Location(point1.latitude, point1.longitude);
Location location2 = new Location(point2.latitude, point2.longitude);
float distanceInMeters = location1.distanceTo(location2);

what is the latitude longitude relation with the Poles(North, South, East, West)?

I am trying to Understand that What happens to the Latitude longitude when moving to North or south or east or West.
Suppose My current GPS coordinates are;
Latitude = 33.659832 Longitude = 72.345678
Now what will be New Latitude/Longitude 30 METERS to the North of my position also tell me towards south, east and west direction.
Please be specific thanks
Latitude is related to South -> North
If you move North, the latitude increases, if moving south it decreases.
Longitude is related to West -> East
If you move East, the longitude increases until 180 and when you cross that datum limit it jumps to -180.
If you want to calculate a new coordinate by offset meters and direction,
you find code here at stackoverflow.
To play with coordinates you can use http://www.geomidpoint.com/destination/
where you enter the coordinate and the offset in km, and the compass direction in degrees.
The calculation is done either using
complex spherical formulas for calculation of big distances > 1km - 10km or
using school mathematics (Polar coordinates (r, phi) once you have
converted the lat, lon to cartesian space, e.g using a
equirectangular projection. That is suitable only for smaller distances less than about 10km

How to convert a LatLng and a radius to a LatLngBounds in Android Google Maps API v2?

I believe this is a limitation of the recent Google Maps API v2. They have recently added the ability to draw a Circle on the ground - but if you want to position the camera such that it shows the entire Circle, there exists no way to do so.
One can call CameraUpdateFactory#newLatLngBounds(bounds, padding) where "bounds" is a LatLngBounds and "padding" is a distance in pixels. The issue is that there is no way to create a LatLng and a radius into a LatLngBounds.
The constructor for LatLngBounds only takes 2 LatLng instances and generates a rectangle where these are the NW and SE corners.
Just like Risadinha mentioned, you can easily achieve that with android-maps-utils. Just add:
compile 'com.google.maps.android:android-maps-utils:0.4.4'
to your gradle dependencies, use the following code:
public LatLngBounds toBounds(LatLng center, double radiusInMeters) {
double distanceFromCenterToCorner = radiusInMeters * Math.sqrt(2.0);
LatLng southwestCorner =
SphericalUtil.computeOffset(center, distanceFromCenterToCorner, 225.0);
LatLng northeastCorner =
SphericalUtil.computeOffset(center, distanceFromCenterToCorner, 45.0);
return new LatLngBounds(southwestCorner, northeastCorner);
}
EDIT:
Our goal is to calculate two points (LatLngs):
southwestCorner
and
northeastCorner
From the javadoc of the SphericalUtil you can read that 225 and 45 are heading values, and the distanceFromCenterToCorner is the distance. Further explanation of the values in the picture below:
With the javascript library you can draw a circle with a center and radius and then get its bounds.
centerSfo = new google.maps.LatLng(37.7749295, -122.41941550000001);
circle = new google.maps.Circle({radius: 5000, center: centerSfo});
bounds = circle.getBounds();
You could do the same using the android api.
This is totally doable.
The LatLng is the center of your circle correct? What you want to do is inscribe your circle inside of the LatLngBounds (Circle inside a Square problem), so the entire thing will show up on the map.
If you draw this on paper you can see that you have everything you need to calculate your LatLngBounds.
Remember how to find the lengths of the sides of a right triangle?
a² + b² = c²
If you draw a line from the center of your circle to the NW (upper left) corner, and another straight to the Western wall (straight line from center, to the left) of the square you have a triangle. Now you can use the equation above to solve for c since you know the the length of the other sides of the triangle (the circle's radius).
So now your equation becomes
r² + r² = c²
which reduces to
2r² = c²
which further reduces to
c = squareRoot(2) * r
Now you have the distance. This is of course an oversimplification, because the Earth is not flat. If the distances aren't huge, you could use the same equation above, but modified to project a spherical earth onto a plane:
http://en.wikipedia.org/wiki/Geographical_distance#Flat-surface_formulae
Notice this also uses the Pythagorean theorem, same as we did above.
Next you will need to calculate your endpoints (NW, and SE corners) from your center point given a bearing, and the distance you found above.
This post may help: Calculate endpoint given distance, bearing, starting point
Don't forget to convert your degrees to radians when using the equation from the post linked above! ( Multiply degrees by pi/180 )
There is a utility library by Google for that:
http://googlemaps.github.io/android-maps-utils/
Recommended by Google for this task and example code:
http://code.google.com/p/gmaps-api-issues/issues/detail?id=5704
While Bartek Lipinski's answer is correct if your LatLngBounds define a square, most LatLngBounds define rectangles, and as such, the bearings of the North-East and the South-West points from the center will not always be 45 and 255 degrees.
Therefore if you are looking to get the LatLngBounds of a radius from a center for any quadrilateral, use the coordinates of your initial bounds.northeast and bounds.southwest like this (using SphericalUtils):
LatLng northEast = SphericalUtil.computeOffset(center, radius * Math.sqrt(2.0), SphericalUtil.computeHeading(center, bounds.northeast));
LatLng southWest = SphericalUtil.computeOffset(center, radius * Math.sqrt(2.0), (180 + (180 + SphericalUtil.computeHeading(center, bounds.southwest))));
(180 + (180 + x)) calculates the bearing of the South-West point from the center clockwise.

i want to draw circle around my current location excatly 1 kilometers readius

hi friends i want to draw circle around my current location exactly 1 kilometer radius so wat can i do.....i able to draw circle but how to put radius so it becomes exactly one kilometer..
At a high level:
Get the bounding coordinates of your current map view.
Use your coordinates to compute the distance either horizontally or vertically across your map. Convert your distance to meters, if necessary.
Divide your distance in meters by the horizontal or vertical resolution (in pixels) of your map view. This gives you the number of meters per pixel at your current zoom level.
Evaluate 1000 / <meters per pixel> to determine the number of pixels in 1 kilometer at the current zoom level. This is the radius of your circle.
Draw your circle using the radius you got in step 4.

What are the latitude and longitude of a circle?

In Android, if I have a circle's radius and center value, how could I measure the latitude and longitude of about 1 km periphery of that circle?
Horizontal = x-axis = Longitude
Vertical = y-axis = Latitude
Latitude and longitude are terms necessary to define a position on a sphere, where two angles are necessary. These terms have no relevance to a circle, which exists only in one plane.
This is not an easy problem to solve as the distance between each latitude and longitude varies depending upon where on the globe you are (I'm sure some maths boffin could do it, but it is beyond me). For instance at the north and south pole one degree longitude measures no distance at all, but at the equator one degree can be several kilometers. If however your search only relates to a small are of the globe, then a you can make a reasonable approximation by using 1km = x degrees where x is the correct value where you are.
Terms "circle", "radius" implies a 2D flat plane geometry whereas "latitude", "longitude" implies a geographical coordinates on a 3D ellipsoid.
Putting these problems asides, let's assume, in fact that your "circle" is a point on the surface of our Earth and, the "radius" is a distance from this point. This will correct your terms so they define a 3D problem.
If a projection is given. Then we can specify the "center" in planar geometry coordinates (X, Y). We can specify all points distance "R" in geometry coordinates as (X + R * cos(phi), Y + r * sin(phi)) then we can use the projection to convert the geometry coordinates from planar to geographic i.e. longitude, latitude. The problem is 1000s of projections exists and not all a valid across the entire Earth.
Alternatively, you can define your 3D ellipsoid in 3D space using (X, Y, Z) coordinates. Then the wording of your problem must change. The "circle" because a sphere whose point is on the surface of the ellipsoid and the "radius" is the radius of the sphere. To compute all points distance "R" from the sphere you will need to intersect the sphere with the ellipsoid using trigonometry. After you have done this, you can convert the resultant 3D coordinates back to longitude, latitude based on the definition of your ellipsoid.

Categories

Resources