1
I own a ArrayList
that stores GPS coordinate objects and their elements are always being compared with the double values returned by the methods getLatitude()
and getLongitude()
of Interface Location.
Problem
From the tests I’ve done I found it very difficult that the Smartphone user capture a GPS coordinate exactly like any of the elements of my ArrayList
. So the solution I find for this problem, is to round up the values double
of the objects of my ArrayList
and also round the double values returned by the methods getLatitude()
and getLongitude()
of Interface Location, to be able to detect more successfully when the user is near the places I intend to control.
Can anyone tell me how best to round up the doubles returned by the methods getLatitude()
and getLongitude()
or indicate another solution to this problem?
Down below follows my ArrayList
:
ArrayList<Coordenada> coordenadasPKs = new ArrayList<>();
coordenadasPKs.add(new Coordenada(41.148185, -8.584755, 336.1));
coordenadasPKs.add(new Coordenada(40.82614, -8.59654, 296));
coordenadasPKs.add(new Coordenada(40.168235, -8.62813666666667, 199));
coordenadasPKs.add(new Coordenada(39.69546, -8.50684666666667, 135));
coordenadasPKs.add(new Coordenada(39.6148033333333, -8.49502833333333, 125));
coordenadasPKs.add(new Coordenada(39.411415, -8.52799166666667, 99));
coordenadasPKs.add(new Coordenada(39.1335366666667, -8.761665, 59));
Already tested how it keeps using
Math.round()
of life?– user42676
i had to do this once with php to generate a more "precise" google map in case I didn’t arredondei , I only limited the houses because the latitudo is compasta for seconds degrees in case I limited to minutes
– Jasar Orion
calculates all distances by Italics and picks up the object that generated the smallest of them
– guijob
@Gamen, the problem I find in the Math Class round() method, is that it makes a rounding to a very short and inaccurate value.
– Vitor Mendanha
@J. William, could you give me an example of how to do this?
– Vitor Mendanha
@Vitormendanha Cara, I don’t know if it’s the best way to do this, I actually think it’s the worst possible, but have you ever thought about doing a cast of the value in a String, format it to two decimal places, sla, as many as you like, and then convert to double again?
– user42676
@Gamen, I have tried unsuccessfully to use the Class: Decimalformat numberFormat = new Decimalformat("#.000"), to round the Latitude and Longitude values of the Location object and the Arraylist objects. I hoped to find other solutions that were more precise...
– Vitor Mendanha
Here is a Haversine Java implementation, which calculates distance between 2 coordinates: http://stackoverflow.com/questions/23776344/haversine-formula-in-java-producing-incorrectresult - you can use this to evaluate the user’s closest points.
– Bacco