Get Accuracy of myLocationOverlay - android

Is there a way to get the accuracy of the fix from MyLocationOverlay? It obviously knows how accurate it is since it draws the circle of the area of how accurate it is. Is there away to get this value?
Thanks

Code from my location listener in one of my apps...
public void onLocationChanged(Location location) {
currentLatitudeE6 = (int) (location.getLatitude() * 1E6);
currentLongitudeE6 = (int) (location.getLongitude() * 1E6);
currentAccuracy = location.getAccuracy();
hasCurrentPosition = true;
gpsMessage = "GPS Tracking";
updateMap();
}

Implement Location Listener by locationManager.requestLocationUpdates method, check following link:
http://hejp.co.uk/android/android-gps-example/

Related

Android mapview geopoint difference emulator and device

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?
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.

Android - Getting coordinates out of GeoPoint-Object

look at this:
MyLocationOverlay myLocationOverlay = new MyLocationOverlay(this, mapView);
myLocationOverlay.enableMyLocation();
myLocationOverlay.enableCompass();
GeoPoint myGeoPoint = myLocationOverlay.getMyLocation();
That works fine. But i need to save the coordinates in a variable. So i tried this:
myLocationLon = (double) myGeoPoint.getLongitudeE6();
When i run the App, this last line makes it collapse. Can you please tell me why this doesn't work ? Thank you
GeoPoint.getLongitudeE6() and GeoPoint.getLatitudeE6() both return microdegrees (basically degrees * 1E6).
so you need to convert microdegrees to degrees simply write function:
public double microDegreesToDegrees(int microDegrees) {
return microDegrees / 1E6;
}
and then
myLocationLon = microDegreesToDegrees(myGeoPoint.getLongitudeE6());

How to get more accurate gps readings in android app?

Im using this code for getting the location for my app:
LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000L, 200.0f, this);
But when i tried the app in my real android phone it show this location about 80 kilometers away from the location im actualy at.. How would i make this code more accurate.. I want the result to be way more accurate for what im making..
Im using the onLocationChanged to display it at the map.. Here it is:
public void onLocationChanged(Location location) {
if (location != null) {
//Gets users longitude and latitude
lat = location.getLatitude();
lng = location.getLongitude();
//sets the GeoPoint usersLocation equal lat and lng
userLocation = new GeoPoint((int) lat * 1000000, (int) lng * 1000000);
OverlayItem usersLocationIcon = new OverlayItem(userLocation, null, null);
LocationPin myLocationPin = new LocationPin(userIcon, MainActivity.this);
//Removes the previous location
if(previousLocation != null)
mainMap.getOverlays().remove(previousLocation);
myLocationPin.getLocation(usersLocationIcon);
overlayList.add(myLocationPin);
//refresh the map
mainMap.invalidate();
//Making myLocationPin into the previousLocation just to be able to remove it later
previousLocation = myLocationPin;
}
The call requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000L, 200.0f, this); is asking to be updated no more than once every 1000ms when the location from GPS changes by more than 200.0 meters from the last update. If you want finer precision, try lowering these numbers.
However, you shouldn't be off by 80km. Are you testing this outside with a clear view of the sky?
I think the issue is with rounding. You are using new GeoPoint((int) lat * 1000000, (int) lng * 1000000);, but instead do this:
new GeoPoint((int) (lat * 1e6), (int) (lng * 1e6));
The difference is, the double values were converted to integers before the multiplication. This way the multiplication happens afterwards, and so the digits after the decimal point are maintained.
There are 2 possible answers...
You can either ask for fine permission, this uses nearby wi-fi networks along with GPS in order to get a better track on where you are:
http://developer.android.com/reference/android/Manifest.permission.html#ACCESS_FINE_LOCATION
or you might just be getting bad GPS data. Have you tried to restart the phone? Are you getting the correct location in Google Maps?
Hope this helps.

Problem generating GeoPoint in Android

I'm trying to create GeoPoints, but I couldn't so far.
double latitudeUpperLeft = -34.567645;
double longitudeUpperLeft = -58.497734;
double latitudeBottomRight = -34.62558;
double longitudeBottomRight = -58.42495;
GeoPoint geoPointUpperLeft = calculateGeoPoint(latitudeUpperLeft, longitudeUpperLeft);
GeoPoint geoPointBottomRight = calculateGeoPoint(latitudeBottomRight, longitudeBottomRight);
This is the helper method:
public static GeoPoint calculateGeoPoint(double latitude, double longitude) {
Double latE6 = latitude * 1E6;
Double lngE6 = longitude * 1E6;
return new GeoPoint(latE6.intValue(), lngE6.intValue());
}
I'm getting an InvocationTargetException on the return of the helper method, What could be wrong?
Thanks. Guillermo.
can you tell me if this works.
public static GeoPoint calculateGeoPoint(double latitude, double longitude) {
return new GeoPoint((int)(latitude * 1E6), (int)(longitude * 1E6));
}
I've found the answer in the anddev.org forum.
The problem was in the manifest, somehow it was missing this entry:
<uses-library android:name="com.google.android.maps" />
After adding it, it started to work.
If you want to use Directly GeoPoint .You will follow the steps:
1)First you have data(Location) in degree formate.
2)By the Equation you have to multiply it by 1000000
3)now ,you have particular GEO POINT Location .
Like here ;if I have location like : Latitude:23.0395677 and Longitude:72.5660045° So, your GeoPoint(23039568,72566045);
You get the Perfect Location for it.

How to set mapview to not show my current location?

how to coding to set mapview don't show the current location
now it's not show on emulater but when I try to install on my mobile , the current location sigh will show
What should I do?
public static int getCoordinateE6(double coordinate) {
return (int) (coordinate * 1E6);
}
GeoPoint geoPoint = new GeoPoint(
GoogleMapServiceHelper.getCoordinateE6(latitude),
GoogleMapServiceHelper.getCoordinateE6(longitude));
getMapView().getController().animateTo(geoPoint);

Categories

Resources