vendredi 27 février 2015

Why i Getting Gps location Null all time..?? Netwrok location working perfect


Vote count:

-1





import android.app.Service; import android.content.Context; import android.content.Intent; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.os.IBinder; import android.util.Log;


public class AppLocationService extends Service implements LocationListener {


protected LocationManager locationManager; Location location; Location l;


private static final long MIN_DISTANCE_FOR_UPDATE = 5; private static final long MIN_TIME_FOR_UPDATE = 6000;


public AppLocationService(Context context) { locationManager = (LocationManager) context .getSystemService(LOCATION_SERVICE); }


public Location getLocation(String provider) { if (locationManager.isProviderEnabled(provider)) { locationManager.requestLocationUpdates(provider, MIN_TIME_FOR_UPDATE, MIN_DISTANCE_FOR_UPDATE, this);



if (locationManager != null) {
location = locationManager.getLastKnownLocation(provider);

Log.v("loc", location + "");
return location; }

} return null; }


@Override public void onLocationChanged(Location location) {


}


@Override public void onProviderDisabled(String provider) { }


@Override public void onProviderEnabled(String provider) { }


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


@Override public IBinder onBind(Intent arg0) { return null; }


}


2



package com.javapapers.android.androidgps;


import android.app.Service; import android.content.Context; import android.content.Intent; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.os.IBinder; import android.util.Log;


public class AppLocationService extends Service implements LocationListener {



protected LocationManager locationManager; Location location;
Location l;

private static final long MIN_DISTANCE_FOR_UPDATE = 5; private


static final long MIN_TIME_FOR_UPDATE = 6000;



public AppLocationService(Context context) { locationManager =


(LocationManager) context .getSystemService(LOCATION_SERVICE); }



public Location getLocation(String provider) { if


(locationManager.isProviderEnabled(provider)) { locationManager.requestLocationUpdates(provider, MIN_TIME_FOR_UPDATE, MIN_DISTANCE_FOR_UPDATE, this);



if (locationManager != null) {
location = locationManager.getLastKnownLocation(provider);

Log.v("loc", location + "");
return location; }

} return null; }

@Override public void onLocationChanged(Location location) {

}

@Override public void onProviderDisabled(String provider) { }

@Override public void onProviderEnabled(String provider) { }

@Override public void onStatusChanged(String provider, int status,


Bundle extras) { }



@Override public IBinder onBind(Intent arg0) { return null; }


}





asked 3 mins ago







Why i Getting Gps location Null all time..?? Netwrok location working perfect

Aucun commentaire:

Enregistrer un commentaire