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
Related
I am trying to create a hill finder application
Like this
The user enters a starting location, and an end location. With the end goal of displaying a chart with the elevations of the road in the trip
Currently, I have managed to get it to create a route between point A and point B. I needed to use routing, since in my use case, the user has to stay on the road and can't just draw a straight line
code so far:
RoadManager roadManager = new OSRMRoadManager(requireContext(), "MY_USER_AGENT");
ArrayList<GeoPoint> waypoints = new ArrayList<>();
waypoints.add(startPoint);
GeoPoint endPoint = new GeoPoint(48.069842, -1.712637);
waypoints.add(endPoint);
Road road = roadManager.getRoad(waypoints);
Polyline roadOverlay = RoadManager.buildRoadOverlay(road);
map.getOverlays().add(roadOverlay);
map.invalidate();
Drawable nodeIcon = getResources().getDrawable(R.drawable.ic_baseline_location_on_24);
for (int i=0; i<road.mNodes.size(); i++){
RoadNode node = road.mNodes.get(i);
Marker nodeMarker = new Marker(map);
nodeMarker.setPosition(node.mLocation);
nodeMarker.setIcon(nodeIcon);
nodeMarker.setTitle("Step "+i);
map.getOverlays().add(nodeMarker);
}
Took this from the guide on the osmdroid bonus pack github page
I already have a system in place to load elevations from coordinates elsewhere in the app. I just need to get the coordinates from the route. At least every 10 feet or so, not just the intersections
I'm hoping this is possible with osmdroid, especially since this has been done with google's apis. However, that code was not open, and I don't want to be charged per usage
My best guess was something with projection(), but I barely know how to use it
NOTE: I won't be using this for long distances, probably at most a mile is what the user would need
I don't think omsdroid can do this out of the box. However you can solve this:
roadOverlay.getPoints() will give you ArrayList containing the "turning" points. You can then apply some math to calculate what you need. I would do it like this:
Calculate distance in feet between two turning points. Calculate distance between 2 GPS coordinates
Divide the distance by 10 feet (as mentioned in your post) and subtract 1. You will get the number of points between the 2 turning points.
Apply some more math to get lat and lng of each of the points on the road. You can inspire here. How to calculate the points between two given points and given distance? or Calculate point between two coordinates based on a percentage
You can now use the elevation API for the points. Do not forget to get the elevation of the turning points, too.
Get the next 2 turning points and repeat. :-)
I am using android to scan WIFI AP's every frame of time, I am getting from each AP the Strength of Signal (RSSI in dbm) and I am calculating the distance with this formula:
public double calculateDistance(double levelInDb, double freqInMHz) {
double exp = (32.44 - (20 * Math.log10(freqInMHz)) + Math.abs(levelInDb)) / 20.0;
return Math.pow(10.0, exp);
}
That is working fine, So I have three or more distances, now I need to draw on a map all AP's with its fixed locations, I made some reading on internet and I found the Trilateration (is the process of determining absolute or relative locations of points by measurement of distances) but it looks like I need at least one Point (x,y), at this moment I just have the calculated distances from the Signal Strength that can be taken as the radius of the different circumferences.
I am confused because I don't have any concrete point (x,y) to start to calculate the location of the Mobile Phone.
I just need to know if there is a way to calculate that point or I can assume that initial point or I am missing something.
Thank you, I really appreciate any.
As Paulw11 mentioned is his comment, you have to know the exact position of all of the APs or at least the one of them and the relative position of the other twos to this one. Then the Trilateration procedure will produce one circle for each AP and the interception of them will be the device.
Keep in mind that the Trilateration with Wi-Fi will produce an area instead of a point which will result in an area of uncertainty with an accurancy of at least 2-3m. And from what I can see you are calculating the distance based on the free space loss model which is a generic type and it is not the truth for each environment, so, this assumption will make even worse your estimation.
A good approach is to make a radio mapping of your area first with Wi-Fi measurements from the device and then be based on this Wi-Fi fingerprints. Or prepare a training period first. There are many tutorials on that.
I am making a java program that classifies a set of lat/lng coordinates to a specific rectangle of a custom size, so in effect, map the surface of the earth into a custom grid and be able to identify what rectangle/ polygon a point lies in.
The way to do this I am looking into is by using a map projection (possibly Mercator).
For example, assuming I want to classify a long/lat into 'squares' of 100m x 100m,
44.727549, 10.419704 and 44.727572, 10.420460 would classify to area X
and
44.732496, 10.528092 and 44.732999, 10.529465 would classify to area Y as they are within 100m apart.
(this assumes they lie within the same boundary of course)
Im not too worried about distortion as I will not need to display the map, but I do need to be able to tell what polygon a set of coordinates belong to.
Is this possible? Any suggestions welcome. Thanks.
Edit
Omitting projection of the poles is also an acceptable loss
Here is my final solution (in PHP), creates a bin for every square 100m :
function get_static_pointer_table_id($lat, $lng)
{
$earth_circumference = 40000; // km
$lat_bin = round($lat / 0.0009);
$lng_length = $earth_circumference * cos(deg2rad($lat));
$number_of_bins_on_lng = $lng_length * 10;
$lng_bin = round($number_of_bins_on_lng * $lng / 360);
//the 'bin' unique identifier
return $lat_bin . "_" . $lng_bin;
}
If I understand correctly, you are looking for
a way to divide the surface of the earth into approximately 100m x 100m squares
a way to find the square in which a point lies
Question 1 is mission impossible with squares but much less so with polygons. A very simple way to create the polygons would to use the coordinates themselves. If each polygon is 0.0009° in latitude and longitude, you will have approximately square 100m x 100m grid on the equator, put the slices will become very thin close to the poles.
Question 2 depends on the approximation used to solve the challenge outlined above. If you use the very simple method above, then placing each coordinate into a bin is just a division by 0.0009 (and rounding down to the closest integer).
So, first you will have to decide what you can compromise. Is it important to have equal area in the polygons, equal longitudinal distance, equal latitude distance, etc.? Is it important to have four corners in the polygon? Is it important to have similar or almost similar polygons close to the poles and close to the equator? Once you know the limitations set by your application, choosing the projection becomes easier.
What you are trying to do here is a projection onto a flat surface of an ellipsoid. So as long as your points are close together, and, well, you don't mind getting the answer slightly wrong you can assume that your projection plane intersects in the centre of your collection of points, and, each degree of lat and lon are a constant number of metres. Then the problem is a simple planar calculation.
This is wrong, of course. I would actually recommend that you look into map projections, pick one that makes sense, and go for that. Remember that you can move the centre of the projection to the centre to your set of points which will reduce distortion.
I suspect that PROJ.4 might help you in terms of libraries. There also must be a good Java one but that is not my speciality.
Finally you can could assume that the earth is a sphere and do your calculations on the sphere. Or, if you really want to get it right you can pick a standard earth ellipsoid and do the calculations on that.
I am trying to practice my skills with using latitude and longitude and I'm attempting to determine the following: given a center point X on a map and a point around it called Y, how do I tell whether or not the points around the center are moving away from the center object or towards it using latitude and longitude?
Right now I have the center latitude and longitude and am focusing on one of the points around it. I have used the Haversine method to calculate distance in miles between two lats and longs. Using this I measured the initial distance the from X to Y and assigned it to a variable. Upon Y's first move I recalculated the overall distance from X to Y and compared it with the initial. If the new measurement is greater than the old then your distance from the point X is increasing, if not it's decreasing. Also, I have check to make sure what I'm working with the point Y is ACTUALLY moving some distance with each move, not just going around the radius of point X in some weird fashion.
Is the way I'm doing things sound alright? I keep feeling like I need to fine tune something but I just can't put my finger on it.
Hopefully everything I'm saying makes sense and is not falling on deaf ears and this doesn't get flagged as an non-constructive question. It definitely is.
Yes, this is the correct way, I have done this some years ago:
In praxis you get the coordinates from a GPS device. Therfore you may consider additional filtering, e.g ignore situtions where the device stands still. Because this may introduce positional jumps.
In your question I saw that you already use a filtering by distance moved: this is suitable!
You can use the haversine formula, like you propose. For high load situations, there are faster distance formulas, for your task (small distances), which do not need so much trigonometric calls, but this is a minor topic.
Overall goal: Given a list of points in 3-dimensional space, I need to generate a sphere around that point given the point's radius and then pro grammatically check if there is space between two or more spheres given a certain point.
Problem: I'm having trouble thinking of a data structure to represent a grid of points (that represent the center of the sphere) and the surrounding sphere, these may not always be hole numbers.
Example Data:
Point A: (-3, .25, 4) Radius: 1.35
Point B: (5, 6.35, 1) Radius: 2
Point C: (1, 0, -1) Radius: .5
My original idea was to have a 3-dimensional array of integers that was of size the absolute value of the maximum and minimum values of the axes added together divided by the smallest accuracy you wanted. You would then use a conversion factor to convert from the array location (whole integers) to the decimal location of a point you were looking for. I would then fill in the array with some data to represent that a sphere exists around the sphere center.
What I'm looking for is the data structure I should use to represent this 3d grid of non-whole numbers. I feel like my technique isn't correct.
This is in Java.
Any and all help is greatly appreciated, thanks!
Why not just represent them with the 3 coordinates x,y,z (3d-point) and the radius, just as you listed them and use (3dimensional) distance to evaluate if points are inside a sphere or not?
Or am I missing the use case here? This sounds like it: "check if there is space between two or more spheres given a certain point"
I actually did something very similar earlier this week.
What I did is decide the minimum distance two points are allowed to have (here for you found by adding the radii of your two spheres if I understood you correctly). Using this I created a random field of spheres using a starting sphere at (0, 0, 0) and then incrementally add extra spheres a random distance away from that.
Since in my case (not sure if you need this as well) I also had a maximum distance I just shifted the coordinates of one of the already accepted spheres and check whether the distances matched.
So, to summarize:
Have a starting point
Randomly place a point (within a specific range) to one of your existing points
Check if it meets your spacing restrictions
Repeat 2-3 until you have enough spheres.
Hope that's any help to anybody.