Why doesn't onLocationChanged method get called in service? - android

I am getting my current location in the form of latitudes and longitudes. My problem is that once I get the coordinates it doesn't get updated when I move to another location.I think onLocationChanged method is not getting called. I read here http://www.lengrand.fr/2013/10/onlocationchanged-is-never-called-on-android/ that it doesn't get called by itself. I have gone through most of the tutorials and can't find a solution.So how can I call onLocationChanged method in my service. Please suggest me step by step.
My codes are as follow:
public class GPSTracker extends Service implements LocationListener {
public Location getLocation() {
try {
locationManager = (LocationManager) mContext
.getSystemService(LOCATION_SERVICE);
// getting GPS status
isGPSEnabled = locationManager
.isProviderEnabled(LocationManager.GPS_PROVIDER);
// getting network status
isNetworkEnabled = locationManager
.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if (!isGPSEnabled && !isNetworkEnabled) {
// no network provider is enabled
} else {
this.canGetLocation = true;
if (isNetworkEnabled) {
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
Log.d("Network", "Network");
if (locationManager != null) {
location = locationManager
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
}
}
}
// if GPS Enabled get lat/long using GPS Services
if (isGPSEnabled) {
if (location == null) {
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
Log.d("GPS Enabled", "GPS Enabled");
if (locationManager != null) {
location = locationManager
.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
}
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return location;
}
}
#Override
public void onLocationChanged(Location location) {
getLocation();
}

Make sure you requestLocationUpdates(...) from the LocationManager (which in your case it seems you do)
If your inside a building and your device doesn't get GPS fix onLocationChanged(...) is not called, I had the same issue (when debugging in my home) but going outside I saw that the function is called once GPS fix is retrieved.

try
#Override
public void onLocationChanged(Location location)
{
Toast.makeText(getApplicationContext(), "My Position !!!"+ location.getLatitude + location.getLongitude,
Toast.LENGTH_LONG).show();
}

It is weird that you are even getting a single location update. From you code it looks like you call getLocation() when you recieve a location change, but you then only setup your location requests inside of the getLocation() function (i.e. you should never enter the getLocation() function). This is how I implemented a location listener for gps data:
Note: I used this in a service, but I did not have my service implement LocationListener.
private void setupLocationUpdates() {
// Acquire a reference to the system Location Manager
mLocationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
// Define a listener that responds to location updates
mLocationListener = new LocationListener() {
// Called when the location has changed.
public void onLocationChanged(Location location) {
mLocation = location;
}
}
// Called when the provider is disabled by the user.
public void onStatusChanged(String provider, int status, Bundle extras) {
Log.d(TAG, "Status Changed: " + String.valueOf(status) + " Provider:" + provider);
}
// Called when the provider is enabled by the user.
public void onProviderEnabled(String provider) {
if(provider.equalsIgnoreCase("gps")) setNotification(Constants.GPS_ENABLED);
Log.d(TAG, "Provider: " + provider + " ENABLED");
}
// Called when the provider status changes.
public void onProviderDisabled(String provider) {
if(provider.equalsIgnoreCase("gps")) setNotification(Constants.GPS_DISABLED);
Log.d(TAG, "Provider: " + provider + " DISABLED");
}
};
mlocationProvider = LocationManager.GPS_PROVIDER;
// Register for location updates
mLocationManager.requestLocationUpdates(mlocationProvider, 0, 0, mLocationListener);
// Add a GPS Listener to notify when searching for signal and when fix is acquired
mGpsListener = new GpsListener();
mLocationManager.addGpsStatusListener(mGpsListener);
}

Related

Android GPS networkProvider not working

In my application, I tried to search the coarse location of the android device using the networkProvider. I only use the networkProvider in my location manager, but it won't work if I don't turn on the GPS sensor on.
Is the networkprovider supposed to give a coarse location no matter the GPS sensor is on or off?
Here's my code.
public Location getLocation() {
try {
locationManager = (LocationManager) mContext
.getSystemService(LOCATION_SERVICE);
if(isNetworkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER))
Log.e("Network","suc");
else
Log.e("Network", "fail");
if (!isNetworkEnabled) {
} else {
this.isGetLocation = true;
if (isNetworkEnabled) {
Log.e("GpsInfo", "isNetworkEnabled true");
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
if (locationManager != null) {
Log.e("GpsInfoClass", "Location manager not NULL");
location = locationManager
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (location != null) {
lat = location.getLatitude();
lon = location.getLongitude();
Log.e("GpsInfoClass", lon + ", " + lat );
}else{
Log.e("GpsInfoClass", "Location NULL");
}
}else{
Log.e("GpsInfo", "Location Manager is null");
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return location;
}
In my log, it prints Network(tag) fail(log).
What this mean is that,
locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)
always returns false, if the GPS sensor is off. Why is this happening? What am I missing about getting coarse locations?
Is the networkprovider supposed to give a coarse location no matter the GPS sensor is on or off?
No, the GPS radio has nothing to do with getting Network Location.
However, you need to have your Location Settings set to either Power Saving or High Accuracy.
Using this code to show a Toast with the current enabled providers:
LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
isGpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
isNetworkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
Toast.makeText(context, "GPS Enabled: " + isGpsEnabled + " Network Location Enabled: " + isNetworkEnabled, Toast.LENGTH_LONG).show();
Here is what it shows for GPS only and Power Saving:
So, you can see that this call:
locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
Returns false for the GPS Only setting, since that disables Network Location.
And, it returns true for the Power Saving setting.
It would also return true for High Accuracy as well, since that enables both GPS and Network Location.
GPS sensor only needed for exact location. If you create a Criteria and give it to locationManager, system automatically selects best provider and tries get coordinates.
Example;
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria locationMode = new Criteria();
locationMode.setBearingRequired(false);
locationMode.setSpeedRequired(true);
locationMode.setAccuracy(Criteria.ACCURACY_MEDIUM);
locationManager.requestSingleUpdate(locationMode, new LocationListener() {#Override
public void onLocationChanged(Location location) {
}
#Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
#Override
public void onProviderEnabled(String provider) {
}
#Override
public void onProviderDisabled(String provider) {
}
}, null);
}

Android: GPS is giving last saved location

I am working on getting current location through GPS. But GPS is always giving me last saved location!
May be it is because of this line! I am looking for better solution!
locationManager
.getLastKnownLocation(LocationManager.GPS_PROVIDER);
Here is Sample Code
if (isGPSEnabled) {
if (location == null) {
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
Log.d("GPS Enabled", "GPS Enabled");
if (locationManager != null) {
location = locationManager
.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
}
}
}
}
Thanks in Advance!
If you use
locationManager .getLastKnownLocation(LocationManager.GPS_PROVIDER);
it will only return the last location saved by the GPS internally.
as you have already added a listner you can get the next changed location on the onLocationChanged overrided function which will be the closest location you need.
There is no way rather than this you need to wait till the onLocationChanged function to be triggered automatically...
Easy implementation is for you that you need to take an location listener
Don't forget to add the permission
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
You can get the frequent update of location change in below listener.
private final LocationListener mLocationListener = new LocationListener() {
#Override
public void onLocationChanged(final Location location) {
//your code here
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
}
}
};
you have to registered it in on create
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, LOCATION_REFRESH_TIME,
LOCATION_REFRESH_DISTANCE, mLocationListener);
//first time you can take the value from the lastKnown location
if (locationManager != null) {
Location=locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
}
}
}

Android GPS using old locations

Im trying to learn more about location services in android and am attempting to build an app which can locate an Android device and send it's latitude and longitude to a server. I've had everything working as expected for a while, but am still being bothered by a small bug. When I send the command from the server to locate the device the first time, the device returns a recent, but old, location such as a road I drove on the same day.
On the second time the device receives a command from the server to locate the device, the device returns an accurate location.
Here is the relevant code:
LocationTracker.java
public class LocationTracker extends Service implements LocationListener {
//flag for GPS Status
boolean isGPSEnabled = false;
//flag for network status
boolean isNetworkEnabled = false;
boolean canGetLocation = false;
Location location;
double latitude;
double longitude;
//The minimum distance to change updates in metters
private static final long MIN_DISTANCE_CHANGE_FOR_UPDATES = 10*1000; //10,000 meters
//The minimum time beetwen updates in milliseconds
private static final long MIN_TIME_BW_UPDATES = 1000 * 60 * 10000; // 10,000 minutes
//Declaring a Location Manager
protected LocationManager locationManager;
public void fetchLocation(Context context) {
getLocation(context);
if (canGetLocation())
{
String stringLatitude = String.valueOf(latitude);
String stringLongitude = String.valueOf(longitude);
Log.i("Location: ", stringLatitude + " " + stringLongitude);
new MyAsyncTask().execute(stringLatitude, stringLongitude);
}
else
{
// can't get location
// GPS or Network is not enabled
// Ask user to enable GPS/network in settings
Log.i("Error: ", "Cannot get location");
}
}
public Location getLocation(Context context)
{
try
{
locationManager = (LocationManager) context.getSystemService(LOCATION_SERVICE);
//getting GPS status
isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
//getting network status
isNetworkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if (!isGPSEnabled && !isNetworkEnabled)
{
// no network provider is enabled
}
else
{
this.canGetLocation = true;
//if GPS Enabled get lat/long using GPS Services
if (isGPSEnabled)
{
if (location == null)
{
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
Log.d("GPS Enabled", "GPS Enabled");
if (locationManager != null)
{
location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
updateGPSCoordinates();
}
}
}
//If no GPS, get location from Network Provider
if (isNetworkEnabled && !isGPSEnabled)
{
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
Log.d("Network", "Network");
if (locationManager != null)
{
location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
updateGPSCoordinates();
}
}
}
}
catch (Exception e)
{
//e.printStackTrace();
Log.e("Error : Location", "Impossible to connect to LocationManager", e);
}
return location;
}
public void updateGPSCoordinates()
{
if (location != null)
{
latitude = location.getLatitude();
longitude = location.getLongitude();
}
}
/**
* Stop using GPS listener
* Calling this function will stop using GPS in your app
*/
public void stopUsingGPS()
{
if (locationManager != null)
{
locationManager.removeUpdates(LocationTracker.this);
}
}
/**
* Function to get latitude
*/
public double getLatitude()
{
if (location != null)
{
latitude = location.getLatitude();
}
return latitude;
}
/**
* Function to get longitude
*/
public double getLongitude()
{
if (location != null)
{
longitude = location.getLongitude();
}
return longitude;
}
/**
* Function to check GPS/wifi enabled
*/
public boolean canGetLocation()
{
return this.canGetLocation;
}
#Override
public void onLocationChanged(Location location)
{
double newLat = location.getLatitude();
double newLong = location.getLongitude();
String stringNewLatitude = String.valueOf(newLat);
String stringNewLongitude = String.valueOf(newLong);
Log.i("New Location: ", stringNewLatitude + " " + stringNewLongitude);
new MyAsyncTask().execute(stringNewLatitude, stringNewLongitude);
}
#Override
public void onProviderDisabled(String provider)
{
}
#Override
public void onProviderEnabled(String provider)
{
}
#Override
public void onStatusChanged(String provider, int status, Bundle extras)
{
}
public IBinder onBind(Intent intent)
{
return null;
}
Why is my location updating as an old location the first time it tries, and a correct location on the second time?
Also note that I would also like to remove requestLocationUpdates seen here:
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
because it causes a handler on dead thread warning, but when I removed it my device stopped acquiring my location. This may be part of the problem.
I would greatly appreciate any help!
It's because you're using getLastKnownLocation().
location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
getLastKnownLocation(String Provider) :
Returns a Location indicating the data from the last known location fix obtained from the given provider.
This can be done without starting the provider. Note that this location could be out-of-date, for example if the device was turned off and moved to another location.

Location only refreshes when I turn GPS off

So I have a problem when trying to resolve my location. When given the command to find my location, it instead gives me the last location of where I turned my GPS off. Being able to find my coarse location using WiFi also seems to not be working.
Here is my current class
public class LocationTracker extends Service implements LocationListener {
//flag for GPS Status
boolean isGPSEnabled = false;
//flag for network status
boolean isNetworkEnabled = false;
boolean canGetLocation = false;
Location location;
double latitude;
double longitude;
//The minimum distance to change updates in metters
private static final long MIN_DISTANCE_CHANGE_FOR_UPDATES = 10; //10 metters
//The minimum time beetwen updates in milliseconds
private static final long MIN_TIME_BW_UPDATES = 1000 * 60 * 1; // 1 minute
//Declaring a Location Manager
protected LocationManager locationManager;
public void fetchLocation(Context context) {
contextnormal = context;
getLocation(context);
if (canGetLocation())
{
String stringLatitude = String.valueOf(latitude);
String stringLongitude = String.valueOf(longitude);
Log.i("Location: ", stringLatitude + " " + stringLongitude);
}
else
{
// can't get location
// GPS or Network is not enabled
// Ask user to enable GPS/network in settings
Log.i("Error: ", "Cannot get location");
}
}
public Location getLocation(Context context)
{
try
{
locationManager = (LocationManager) context.getSystemService(LOCATION_SERVICE);
//getting GPS status
isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
//getting network status
isNetworkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if (!isGPSEnabled && !isNetworkEnabled)
{
// no network provider is enabled
}
else
{
this.canGetLocation = true;
//First get location from Network Provider
if (isNetworkEnabled)
{
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
Log.d("Network", "Network");
if (locationManager != null)
{
location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
updateGPSCoordinates();
}
}
//if GPS Enabled get lat/long using GPS Services
if (isGPSEnabled)
{
if (location == null)
{
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
Log.d("GPS Enabled", "GPS Enabled");
if (locationManager != null)
{
location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
updateGPSCoordinates();
}
}
}
}
}
catch (Exception e)
{
//e.printStackTrace();
Log.e("Error : Location", "Impossible to connect to LocationManager", e);
}
return location;
}
public void updateGPSCoordinates()
{
if (location != null)
{
latitude = location.getLatitude();
longitude = location.getLongitude();
}
}
/**
* Stop using GPS listener
* Calling this function will stop using GPS in your app
*/
public void stopUsingGPS()
{
if (locationManager != null)
{
locationManager.removeUpdates(LocationTracker.this);
}
}
/**
* Function to get latitude
*/
public double getLatitude()
{
if (location != null)
{
latitude = location.getLatitude();
}
return latitude;
}
/**
* Function to get longitude
*/
public double getLongitude()
{
if (location != null)
{
longitude = location.getLongitude();
}
return longitude;
}
/**
* Function to check GPS/wifi enabled
*/
public boolean canGetLocation()
{
return this.canGetLocation;
}
#Override
public void onLocationChanged(Location location)
{
//Want to Execute Asynctask method to HTTP post the lat and long. Is there a way `to pass in a context to do this?`
}
#Override
public void onProviderDisabled(String provider)
{
}
#Override
public void onProviderEnabled(String provider)
{
if (contextnormal != null) {
fetchLocation(contextnormal);
}
}
#Override
public void onStatusChanged(String provider, int status, Bundle extras)
{
}
#Override
public IBinder onBind(Intent intent)
{
return null;
}
I would guess the problem lies in these lines
if (isGPSEnabled)
{
if (location == null)
{
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
Log.d("GPS Enabled", "GPS Enabled");
if (locationManager != null)
{
location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
updateGPSCoordinates();
}
}
And for some reason it is giving the last known location as the last time the GPS was turned on. Any ideas as to why it is doing that instead of giving the last known location as the present location if the GPS is on?
EDIT:
Implementing the following method and testing:
#Override
public void onLocationChanged(Location location)
{
double newLat = location.getLatitude();
double newLong = location.getLongitude();
String stringNewLatitude = String.valueOf(newLat);
String stringNewLongitude = String.valueOf(newLong);
new MyAsyncTask().execute(stringNewLatitude, stringNewLongitude);
}
You can't just query the location manager for its last known location repeatedly, that will only get you the last known location. It sounds like what you are trying to do is get location updates as you move around.
In this case, you will need to register for location updates, as you tried with your line:
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
You are on the right track here, but what is this (the last argument on the function call [yes I know it is a reference to the current class...])? The last argument is supposed to be an intent or a callback where the updates will be broadcast to. It doesn't appear that you have implemented that from the code you provided.
Change your this argument to a class which implements LocationListener. The location updates will come to the onLocationChanged method where you can then process them as you see fit. A simple way to do this is to add a nested inner class which implements the listener, then you can just create an instance of that class and pass it to the location manager, in place of your current this argument.
EDIT
OK, so you are implementing the thing correctly, but blisfully ignoring the location updates, don't do that. The service you have is a Context -- so you can pass that around as you see fit, although it may be better to use:
this.getApplicationContext();
If you are passing it to some long running thing. What I would recommend is to queue your location updates when the arrive in onLocationChanged(). After queuing the location, signal a background worker thread (or AsyncTask) to actually post the location to your web service.
Also, don't override onBind and return null. Just don't override it.

GPS getting me only one location and that never changes Android

in my app I am able to use the GPS but the problem is that it always getting me the same location. Everytime I am retrieving the location from that on, it gives me the same value. First time it was fetched and I was online, wirelessly. Then i went out with only the GPS and even if I was a mile away location was the same. I enabled 3g and still the same.
I send my app to a friend of mine, he got a different first time location and then he sees the same no matter where he goes.
Here is my code:
public Location getLocation() {
try {
locationManager = (LocationManager) mContext
.getSystemService(LOCATION_SERVICE);
// getting GPS status
isGPSEnabled = locationManager
.isProviderEnabled(LocationManager.GPS_PROVIDER);
// getting network status
isNetworkEnabled = locationManager
.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if (!isGPSEnabled && !isNetworkEnabled) {
// no network provider is enabled
} else {
this.canGetLocation = true;
// First get location from Network Provider
if (isNetworkEnabled) {
// System.out.println("Network enabled");
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
if (locationManager != null) {
location = locationManager
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
}
}
}
// if GPS Enabled get lat/long using GPS Services
if (isGPSEnabled) {
// System.out.println("GPS enabled");
if (location == null) {
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
Log.d("GPS Enabled", "GPS Enabled");
if (locationManager != null) {
location = locationManager
.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
}
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return location;
}
#Override
public void onLocationChanged(Location location) {
// mAct.playToastMessage("Location Changed");
getLocation();
// mAct.setGPSText(location.getLatitude(),location.getLongitude());
}
#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;
}
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
In this For the parameter of MIN_TIME_BW_UPDATES and MIN_DISTANCE_CHANGE_FOR_UPDATES you have to set the 0 and 0. If it is set to 0,0. It will give you the location update as quick as possible. If you set larger value for the you never get the updated value until your condition satisfied. I hope this could solves your problem.
#Override
public void onLocationChanged(Location loc)
{
loc.getLatitude();
loc.getLongitude();
String Text = “My current location is: “ +
“Latitude = “ + loc.getLatitude() +
“Longitude = “ + loc.getLongitude();
Toast.makeText( getApplicationContext(),Text,Toast.LENGTH_SHORT).show();
}
Source : Tutorial on GPS to get Current Location.

Categories

Resources