I am developing field area calculator app using gps location.Is there any way to calculate the
area of given gps locations?
You can calculate the area of an polygon that is formed by a sequence of GPS coordinates.
The steps are:
transform the spherical lat/lon coordinates to cartesian space.
Use the general formula for area of polygon.
Code is given in this answer:
Polygon area calculation using Latitude and Longitude generated from Cartesian space and a world file
Use the center of the polygon (or just any point of the polygon) as center of transformation.
In the code in the link, that is called latAnchor and lonAnchor.
Especially if the diameter of the polygon does not exceed some 10 kilometers this approach works well. For large polygons step 1 becomes more complex.
Related
I want to create a map for an indoor location finding App. I have images of the building layouts and how they should look, but I don't know how to show the exact location given some coordinates (X,Y). I only need something simple.
I'm creating an indoor location finding app, based on WiFi signals. The algorithm part returns a pair of coordinates (X,Y), and I want to display the location somehow.
I really don't know how I should do this.
My first thoughts were to get the pixel coordinates of the (0,0) point on the image, and the distance in pixels between two points, i.e (0,0) and (0,1), (I know they are equidistant). The image, the pixel coordinates and distance are stored in an object.
Now, given a pair (X,Y) the object above, I can calculate on which pixel the location should fall on. But this isn't MATLAB, and I'm not sure how to edit it or if I can add a Pin or something on top of the image in order to show the location.
Example:
Here is an image of a building
I know for the point (0,0)(starting from bottom left) pixel coords are (47,223) and the distance between the points is 45px.
Given the coordinates (1,2.5), I have to show the estimated location. Which is the pixel (92,110) and have to highlight it somehow.
This is my only idea, as I'm pretty new to Android developement. It doesn't necessarily have to be like this, I just want to pinpoint a location given a pair of coords (X,Y). I'm open to suggestions.
Thank you for your time.
I need to calculate a polygon area on my mapView. I studied this case, and de Polylines shows the best way to make a area, with the points that the user was informed. But I didn't find the way to calculate his area! Can anyone help me please? Or suggest other alternative to draw polygons and calculate area/perimeter in android application.
convert lat/lon points to cartesian space
Use area of polygon formula you easily find in wiki.
ad 1) if polygons diameter are not more than some 10s of kilomters an EquiRectangular Projection makes sense and is very simple, using the center of the polygon as center of transofrmation (cos (centerLatitude)).
Otherwise task 1 is complex.
I am currently playing a bit with Android and GPS tracking and so forth.
I found out, that I have to call the OSM API with the corner points of the bounding I want to get POIs for example. I would like to achieve, that I get my current cooredinates from the handset (which allready works) and then get some pois from OSM for the bounding box where my current position is the center.
I could imagine a function like that:
public Map getBoundingBox(Double long, Double lat, int meters);
BUT I do not have any idea how to calculate this bounding box.
Could someone give me some hints please?
cheers, christian
I assume that long and lat are given in seconds.
First, you need to calculate width of the rectangle in seconds. One second is 30.9 meters on the equator, for other latitudes, multiply by cos(lat), so to convert it to seconds you do the following:
double widthSeconds = meters / (30.9 * cos(lat));
Second, knowing the center of the box, it's easy to calculate the coordinates of corners:
EDIT: the example above works for Europe and Asia. For other locations, directions of coordinate axes may be different.
I have the coordinates of a player and another object. Both are with geographical coordinates (Latitude and longitude). I have also the direction in what the player is facing (compass). How can I calculate the angle to the other object from the player direction? e.g. I want to know if the object is to the right/left of the player and how many degrees.
Thanks a lot!
With a few it depends, the answer is in essence, you want to know about how to do geographic navigation. One of the reasons it depends is that the distances involve as well as the accuracy needed may influence the answer.
For short distances (<10km) you may be able to ignore the curvature of the Earth, and treat it like a two dimensional Cartesian map (latitude / longitude as X-Y). Then you question becomes basic trigonometry.
For larger distances, or improved accuracy, you can either approximate using an spheroid model of the Earth (assume the Earth is a perfect sphere, which it is not) and calculate the Great Circle bearing and distance.
Or you can model the Earth as an ellipsoid, and calculate its geographic navigation.
Two web pages that may help: Details for computing distance using lat/long coordinates and Calculate distance, bearing and more between Latitude/Longitude points.
Note: atan2 and Haversine formula are often useful implementation details.
Small added note: bearing is a synonym for heading or direction in this context.
You need this spherical trig formula: http://williams.best.vwh.net/avform.htm#Crs Once you have the course (angle relative to true north), you can subtract off the compass heading of the direction the player is facing to get the relative heading.
(I don't know if Android automatically compensates for magnetic variation or not, but if not you'll have to account for it too to get the angle right in all areas)
There are tools in the API to do this for you: Location.bearingTo(Location) and GeomagneticSensor will give you the direction from your position to the target - which you can then adjust based off the devices current heading.
If you've already got a MapView running & are lazy, set up a MyLocationOverlay, enableCompass and skip the GeomagneticSensor and let the MapView do it for you.
Assume that my current point is lat = 50.000 and long = 50.000 and I want to show some bus stations on these location but my limit should depends on zoom level.
So far, for that aim I find a way: If a can take left-up corner and right-down corners lat's long's ; I will find stations between these locations.
Do you know how can I take these points or any different idea about this situation?
Thanks in advance..
Well you can easily get the top left and bottom right lat/lon coordinates using
GeoPoint tlGpt; // Top left
GeoPoint brGpt; // Bottom right
tlGpt = mapView.getProjection().fromPixels(0, 0);
brGpt = mapView.getProjection().fromPixels(mapView.getWidth(), mapView.getHeight());
At any zoom level where you could actually see the bus stations on the map, then the top left longitude could be considered the same as the bottom left longitude, similarly bottom left long would be approx = bottom right long. Thus you could consider the bounding box as a rectangle, rather than an isosceles trapezium (trapezoid in US English)
If you just want a rough measure to pick up a reasonable sample of objects, then lat/long "distance" is good enough. Just make sure you divide the latitude range by the cosine of the latitude, to get the longitude range (i.e., ∆long = ∆lat/cos(lat)). This is to compensate for the contraction of longitude lines as you approach the poles. You use ∆lat as the basis because latitude lines have the same distance between them everywhere on the globe.
For a more accurate measure, there are some complicated functions that allow you to compute great circle distances from lat/long pairs, but it is conceptually much easier to convert lat/long pairs into 3-D coordinates, and use a simple pythagorean distance to approximate the great circle distance. You could use 2*r*acos(d/(2*r)) (if my whiteboard geometry serves me well), where r is the nominal radius of the earth, to get the exact great circle. But if all you want is to get objects within a range, you can invert the formula to get the pythagorean-distance equivalent of the great-circle limit. This can also be used to derive a 3-D bounding box to speed up the search. If your database supports R-trees, then you're laughing! SQLite supports R*Trees, but they are disabled in the default build, so I don't know if they're available on Android (it seems that it isn't).