Android : Android getting Longitude and latitude always returns 0.0

on Saturday, September 20, 2014


I'm trying to get the longitude and latitude for android, here is my code:



LocationManager locationManager = (LocationManager)
this_activity.getSystemService(Context.LOCATION_SERVICE);

LocationListener locationListener = new MyLocationListener();
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, 5000, 10, locationListener);




public class MyLocationListener implements LocationListener {

@Override
public void onLocationChanged(Location loc) {
longitude = Double.toString(loc.getLongitude());
latitude = Double.toString(loc.getLatitude());
}

@Override
public void onProviderDisabled(String provider) {}

@Override
public void onProviderEnabled(String provider) {}

@Override
public void onStatusChanged(String provider, int status, Bundle extras) {}
}


I'm always getting 0.0s for longitude and latitude


0 comments:

Post a Comment