I'm trying to obtain my current location via GPS, but nothing seems to work, I followed many questions here but with little results...
Here's my code:
private GeoPoint getActualPosition()
{
LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
Location current = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
actualLat = (int)(current.getLatitude()*1E6);
actualLong = (int)(current.getLongitude()*1E6);
GeoPoint point = new GeoPoint(actualLat, actualLong);
return point;
}
Now, the "this" part of the method (on requestLocationUpdates) makes reference to the activity who implements the LocationListener interface, where its onLocationChanged method is:
@Override
public void onLocationChanged(Location location) {
actualLat = (int)(location.getLatitude()*1E6);
actualLong = (int)(location.getLongitude()*1E6);
}
My problem is on the current Location line, where "current" is always, always null, and I can't find why.
My manifest has the permissions needed:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
So I don't really know what is wrong with my code.
Thank you for your time!!