longitude and latitude points change for the same place - java

I am Android developer.
I am getting the longitude and latitude point of a place but for the same place these values changes and the third decimal varies.
My main purpose is to detect a place so it works only
when all these values of longitude and latitude matches so they must
be constant.
My questions are:
What is the reason for this variation?
Is there any method by which ti make these values remain constant for a specific place?

The phone's GPS isn't very accurate. That is, it is very accurate for navigate in your car, but missing by 20 meters is not unheard of.
To figure out if you're in the same place, you should calculate the distance between your current location and the place's coordinates. If it's lower than a threshold (try to find one that makes sense) - you're there.

Try using the GPS for more accurate data, but know that they will not be the same values everytime, but not very different either

You can look at the accuracy as well. The Location class has a getAccuracy() method -- if your accuracy decreased from the last method, it may be that the person went inside and lost line-of-sight to the sky.
As I have said before in other posts, I recommend using Google's Play Location service rather than the pure GPS. You can also use an isBetterLocation method as documented here.

As stated above, the GPS inherent accuracy isn't the best. For an idea of how the decimal places show accuracy levels, see the Wikipedia page
In short, the third decimal place results in an accuracy differential of 43-111 meters, depending on your position on the globe. So I would either look at some other method of refining the data, or implementing some sort of threshold processing.

Related

Android Barometer Altitude Reading Is Wrong?

I've been trying to implement a feature to get the correct altitude based on the barometer sensor from Android Galaxy S5 phones. The only problem is, I don't think it is accurate. Based on http://www.whatismyelevation.com on my particular location, it shows that my altitude is around 114 meters. However, on my phone, it shows that it is 210 meters based on the barometer sensor. I am in a tall building, however, but I don't think it is 100 meters tall.
Here is my simple code:
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.configure_settings);
context = getApplicationContext();
mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
sensors = mSensorManager.getSensorList(Sensor.TYPE_PRESSURE);
if (sensors.size() > 0)
{
sensor = sensors.get(0);
mSensorManager.registerListener(this, sensor,
SensorManager.SENSOR_DELAY_NORMAL);
}
}
#Override
public void onSensorChanged(SensorEvent event)
{
float pressure = event.values[0];
altitude = String.valueOf(SensorManager.getAltitude(
SensorManager.PRESSURE_STANDARD_ATMOSPHERE, pressure));
}
Thanks!
First: The barometers are very precise, but not accurate. If you place 10 Android phones next to each other on a table, you can find barometric pressure differences of up to 3 mb between devices. This is one source of error.
Second: Different groups will define 'altitude' differently, so make sure you're using the same definitions. For example, in the Location class, getAltitude is defined as
Get the altitude if available, in meters above the WGS 84 reference ellipsoid.
http://developer.android.com/reference/android/location/Location.html#getAltitude()
Third, the weather will affect the reading of the barometer by up to 40 mb. If you want to get a more accurate altitude reading from the barometer, you will have to offset from the current weather. The atmosphere can change the local pressure by up to 1-2 millibars per hour (in extreme cases)
Fourth: it is not yet possible to get a completely accurate altitude reading using the barometer in a smartphone. Nobody has solved this yet - the barometer alone is insufficient to achieve floor-level detection, for example.
I'm the developer of PressureNet, by the way - I have collected over 2 billion pressure readings from smartphones, and I see all these types of errors every day.
In closing: the reading that the barometer delivers to you requires significant interpretation before using, if you want to achieve a value for 'altitude'. Every value that is read from every barometer is 'wrong' by default; you'll have to do specific work to make it work for you, depending on what your exact needs are.
github.com/cbsoftware/pressurenet
The air-pressure sensor of a smartphone-type device has very poor absolute accuracy. I.e. when you are stationary the value read will probably not be equal to what you read from another source.
It is, however, rather good at measuring changes to the air-pressure. So if you read the air-pressure at one altitude and then quickly move to another altitude you will get a fairly accurate measure of the difference in altitude (provided you use the right altitude formula, ex. https://physics.stackexchange.com/questions/333475/how-to-calculate-altitude-from-current-temperature-and-pressure)
I.e. if you know the absolute altitude at one of your locations you can compute a rather accurate value for the other location.
It is also important to remember that air-pressure for any location is variable due to weather changes. In a windy environment you will generally find that values are less accurate unless you do some time-averaging or low-pass filtering of the values.
When it comes to altitude values served by Google, the GPS or other sources they generally refer an altitude for a location to an idealized shape of the earths surface. This shape is typically called a geoid (a spheroid shape that rather closesly resembles the actual shape of our globe). The actual surface of the globe, that be either land or ocean, do deviate in shape from the ideal geoid in most places. For areas that were covered by thick layers of ice during the last ice-age the land may still be 30-50 meters below the geoid reference. More details are found here: https://www.esri.com/news/arcuser/0703/geoid1of3.html.
For normal mapping purposes the altitude is referenced to some form of constant. When close to the sea altitude == 0 at LAT (Lowest Astronomical Tide) and local mapping references to altitude is thus traditionally referenced to this level. Other more 'modern' references are also used. Google, the satellite-based global positioning systems, etc. do not use this reference, hence the altitude you get from them and the altitude you calculate (or read off a map) locally do not generally match.
Just a report for Android 8.1 on Samsung S7 smartphone compared to weather station pressure sensor/algorithms.
Samsung S7 phone=970 millibars
Weather station=1010 millibars (at the same time)
Those are about +/- 2% difference from the arithmetic mean of the two values, 990 millibars.
However, GPS is about 3% error limit for altitude. Within a span of about 5 minutes, consumer grade GPS reports altitude on a hilltop nearby ranged generally from about 1080ft to 1150ft, with isolated readings lower and higher than those. The arithmetic mean is 1115ft, and the lower and upper values are about +/- 3% of the 1115ft value. A National Geodetic Survey map shows the official altitude of the hilltop is 1110ft, which is very close to the mean of the two values.

How can I correctly convert geographical coordinates to pixels on screen?

I'm trying to make a Java project that pinpoints the place on a image of a map, when given coordinates (taken from Google Maps).
I've tried using the top-left corner of the image (place that has highest latitude, and the lowest longitude), as an some kind of an reference point, which would be (0,0) point on the map image, and than I've tried to calculate every place on the map based on that reference point. However, this method proved inaccurate, probably because of the curvature of the Earth (mind that the map I'm working with (Serbia) covers area of 4° latitude, and 4° longitude).
I've seen couple of answers talking about converting into Mercator projection, but they are not very clear to me, because they are not covering a case similar to mine, and are not written in Java.
What can I do to pinpoint those points more accurately (±3km would be accurate enough)?
As comments have pointed oit correctly, in order to precisely convert between geographic coordinates and map position, you have to know the method of projection used for the map, and a sufficient number of parameters so that tuning the remaining parameters using a suitable set of reference points becomes feasible.
So if you assume a conic projection, then read the document David pointed out, and this referenced follow-up as well. As you can see, within the family of conic projections, there are a few alternatives to choose from. Each of them is described by a few parameters (i.e. standard parallels, cone constant, aspect ratio, …). You'd make guesses for these and then use some numerical optimization to obtain a best fit. Then you take the best parameter fit for each kind of projection and see which of them has the best overall fit. Quite a bit of work. If you don't want to implement the code for all these projections you can use proj.4 either on the command line or as a native library. To do the numeric optimization, you could possibly try to adapt one of the COIN-OR projects to your application.
In any case, the first step would be creating a suitable set of reference points which you can use to evaluate the fit. So pick a few prominent points on your map and find Google Earth coordinates for these. I'd say you should have at least a dozen points, to account for the fact that you know so little about your map. Otherwise there is a great risk that you will tune the large number of parameters to exactly fit your points while the rest of the map is still completely off. Even with this number of reference points, since the area of Serbia is not that big (compared to maps spanning whole continents), the errors of a wrong guess or a bad fit might be very small. So it might be hard to actually decide which projection has been used.
With all that I said above, and even with external libraries taking care of the projection and the numerical optimization, it might easily take you half a year just to set up the tools to work out the projection. So decide whether that's worth the effort. If not, there are several alternatives. One would be to take a different map, one where you know the projection. Or contact the author of your map and obtain the projection. Or ask someone working in geodesics in Serbia, because they might have enough experience to recognize the projection at a glance, I don't know.
One other option is by combining the fact that you need reference points with the fact that you might not be able to work out the exact projection in any case. Simply combine these in the following way: choose a suitably dense set of reference points, evenly distributed over the map. Then interpolate between them, picewise linearily or with higher degree or using some weighted interpolation scheme or whatever. You know there is a projection behind all this, but you give up on working out the projection, and simply mitigate the symptom: by having enough reference points, each data item is close enough to a reference point to keep the error smaller than your threshold.
I found an answer I was looking for in this thread: Java, convert lat/lon to UTM
I find out that the actual projection of my map was UTM. From there, it was simply finding a class that would convert my lat/lon coordinates into UTM eastings and northings (very useful code in this answer), and then I would do simple math to find out where the point is compared to the boundaries of the map, and it's actually working.

How to get nearest places (that are user entered) based on current location?

I am building an Android application where users can find nearest places according to their current location and also, be able to add places into the database. I understand that I will have to use long and lat in my database but I really don't know how to compare the current location against the places in the database. How would I even search it because I would potentially have to go through the entire database systematically pulling out each geo point and then comparing it against the user location?
Example:
Say users have entered 10 places in London and 1000 other places all around the world and a person in London is using the application and wants to find places that are nearest to them based on their current location. How would I search for these 10 places among 1000s of other places in the database? Performing distanceTo() a 1000 times is unnecessary.
Any advice, guides, tutorials, references would be great.
Thanks in advance.
EDIT:
This is my idea so far.
Get the longitude and latitude of the location, which could either have been searched, the current location or the location that the user has tapped on the screen.
With Long/Lat of said location - get the place description of the place from reverse geocoding with the getFromLocation method.
With place description, search database based on address string.
This is what I have right now but again this doesn't seem to be reliable. There must be a simpler way to query the database given the long/lat of a location and return back a complete list of the nearest spots.
If you are using latitude and longitude, this should be pretty simple. Let's say the coordinates of the individual are roughly: 49°N, 2°E.
To find all locations with 1 square degree of lat/long, you would just select all locations that satisfied the following criteria:
Latitude >= 48°N and <= 50°N
.. and ..
Longitude >= 1°E and <= 3°E
It's pretty simple.
There's a table on Wikipedia that explains how much decimal degrees are 1 kilometer etc. And the coordinates that you receive from Google are in decimal degrees.
https://en.wikipedia.org/wiki/Decimal_degrees
If you have any more questions on how to calculate etc, just ask :)
Basically you just need to check if the places latitude is higher than
currentLocationLatitude - rangeInDecimalDegrees
and smaller than
currentLocationLatitude + rangeInDecimalDegrees

how to calculate all points(longitude,latitude) within a given radius from given point (longitude,latitude)?

I have a given point (longitude,latitude) and I want to get all the points ranges that comes lets say 5 miles radius in given point?
I'm just guessing here, but I think you'll need to find a different approach. If you're trying to do something like Foursquare, Google Maps, etc where it finds places within a 5-mile radius of your current location, I think you'll find that these services don't calculate all the points in that radius and then match them up to places at those points.
There would probably be some smarts behind the code that do something like this...
Get the users current location
Find the suburb (or failing that, find the city) that the current location exists in. Also find all the surrounding suburbs adjacent to this one.
Find all the places within those suburbs, and calculate how far they are away from the current user location
This kind of process is one potential method that could be employed by these services. This deals with small subset of place comparisons, which is relatively quick to perform. Also, places on a map usually have a suburb/city associated with them anyway, so database lookups for places would be rather quick, as there would be an index that involves the suburb.
If you're aim is to do something like this, I would try to figure out a different way to compare points rather than simply trying to calculate everything in your radius.
And of course, there would also be plenty of specific algorithms for calculating this better, but that's not my area of expertise, and would be better suited to another forum. I'm not trying to say that this is the best way to do it, but there's plenty of other ways to do it that rely on known location data which would be quicker and smarter than your suggested requirement.

coordinates based search

I am developing a web page where users can create activities and others find them via a search function. When you create an activity you must specify the exact location where it will take place, assisted by google maps I retrieve the latitude and longitude. Now, when doing a search I want to have the functionality to find all activities close to a specified location(also assisted by google maps).
So I have a set of activities with coordinates, the coordinates of a point I want to find activities nearby, and I want to return activities that are no more than, lets say, 5 km(or miles or whatever you prefer) away from this point.
I am having this idea in my head that this can be solved by calculating max/min latitude and longitude, and use these as parameters in an sql-query where I use a where clause for filtering...The problem I'm facing here is firstly calculating these max/min values, secondly in an circular area(with radius 5km), and not a rectangular
Would appreciate any input here!
Thanks!:)
Coordinates you get are probably not x and y but latitude and longitude; you will need spherical distance unless all your points are within rather small radius, e.g. few hundred miles.
If you have many points, direct exhaustive search becomes too slow, spherical or not. Fortunately, GIS extensions available both for MySQL and for Postgres. Commercial DBs also have spatial extensions. These make searches for nearby objects efficient.
Calculate the boundary latitudes and longitudes.
Use the inverse http://en.wikipedia.org/wiki/Haversine_formula
Select everything where the latitude is between your two values for that, and similarly for longitude. If you're not using a spatial index, beware of edge cases on your sphere (a most excellent pun!): crossing 0, 90, or 180 degrees may result in impossible criteria.
Either in your SQL server or your app, execute the Haversine formula against your results. You must have the rectangular bounding values to prevent a table scan, but results in the rectangle will include results outside of your circle.
If you actually stop to think about it, your rectangle and your circle are both misshapen... but that's not really relevant anyway.
Also, check out this, which will expand on distance measuring and mention some other ideas: http://www.movable-type.co.uk/scripts/gis-faq-5.1.html
Hope this can help you.
Get nearest places on Google Maps, using MySQL spatial data
However this is MySQl query. You can convert it as your requirement.

Categories