Geolocation - Invalid latitude and longitude in android

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

I testing the below code snippet. I suddenly get a weird location (0,0) as latitude and longitude which disturbs my distance calculation.

if (loc != null) {
                double currentLatitude = loc.getLatitude();
                double currentLongitude = loc.getLongitude();

                if (first_time) {
                    loc.reset();
                    first_time = false;
                }

                synchronized (testObject) {
                    … do some work
                    previousLat = currentLatitude;
                    previousLon = currentLongitude;
                }
            }

I would like to know in what situations does the latitude and longitude become 0. I also would like to know where my code bugs out due to which I am getting 0 latitude and longitude. Is location.reset() results in 0 latitude and longitude?

Answers

Of course it is 0 when you reset it. Why do you do that? which value you would expect when calling reset()? A location delivered by android location services has an acuracy set (getAccuracy()). If you create your own location object or reset() it, it will be 0.

Further info I have written before, shows why i always check the validity before calculating:
lat,lon 0,0 is theoretically a valid location. but in my years of GPS experience, i give you the tipp: ignore all locations with coord (0,0).
This has no impact on real world behavipur, bevause a device cannot be located exactly at 0,0 (with centimeter accuracy), and even if it could, then not more than one second.

If you want you can init your lat,lon with a special value out of the range of the coord range. but even then you are not save from errors of other people.

Generally check if the location is valid, if you have a valid flag,which should exist on android. look at the horicontal accuracy value. read the docu how to distinguish between invalid locations.

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/15656862/invalid-latitude-and-longitude-in-android

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils