I have a problem related to the Location API.
I tried the following code:
LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SER
Along with the permissions in your AndroidManifest.xml file, have you registered a location listener?
LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
Location loc = getLastKnownLocation(LocationManager.GPS_PROVIDER);
lm.requestLocationUpdates(LocationManager.GPS, 100, 1, locationListener);
Then have a method, in this case locationListener, to complete your task
private final LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
latitude = location.getLatitude();
longitude = location.getLongitude();
}