Question

i am getting data from gps provider using mylocation class. code is this:

MyLocation.LocationResult locationResult = new MyLocation.LocationResult() {
        @Override
        public void gotLocation(Location location) {
            //Got the location!

            // for phone
            //currentLocation = new GeoPoint((int) (location.getLatitude() * 1000000),
            //   (int) (location.getLongitude() * 1000000));

            // for emulator
            currentLocation = new GeoPoint((int) (location.getLatitude()),
                    (int) (location.getLongitude()));

            doSomething();

        }
    };
    MyLocation myLocation = new MyLocation();
    myLocation.getLocation(this, locationResult);

when i use the app in emulator(2.3.3) it shows the correct location without multiplying anything.

but when i use it in a device(4.0) lat and lon need to multiplied with 1000000. i couldn't find why. i don't think its because of the version of android. anyone have any idea?

Was it helpful?

Solution

Because the MapView uses microdegress for its units so you need to multiply by 1e6. Otherwise you show up off the coast of Africa - basically lat long of approximately 0,0

From the documentation on GeoPoint:

An immutable class representing a pair of latitude and longitude, stored as integer numbers of microdegrees.

Don't know why the emulator is working - it shouldn't.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top