Rectangle 27 1

In your MainViewModel you need to check if they have allowed location services before you use the geocoordinatewatcher.

if(settings.LocationAllowed)
  {all your code for using location}

windows phone 7 - how to disable location services in my WP7 app - Sta...

windows-phone-7 geolocation
Rectangle 27 1

You should probably take into account a few factors/points, most of which, you have. Anyway, you might find these helpful.

  • Your application settings toggle should only show when the location service is switched on on the device
  • GeoPositionStatus is just an Enum which contains the types of statuses.
  • StatusChanged is the event which is to be handled to check for changes in the device settings. See this.
  • You cannot change the device settings from the application.
  • Add event handlers before you call start on the watcher.

windows phone 7 - how to disable location services in my WP7 app - Sta...

windows-phone-7 geolocation
Rectangle 27 0

The locationServicesEnabled class method only tests the global setting for Location Services. AFAIK, there's no way to test if your app has explicitly been denied. You'll have to wait for the location request to fail and use the CLLocationManagerDelegate method locationManager:didFailWithError: to do whatever you need. E.g.:

- (void)locationManager: (CLLocationManager *)manager
       didFailWithError: (NSError *)error {

    NSString *errorString;
    [manager stopUpdatingLocation];
    NSLog(@"Error: %@",[error localizedDescription]);
    switch([error code]) {
        case kCLErrorDenied:
            //Access denied by user
            errorString = @"Access to Location Services denied by user";
            //Do something...
            break;
        case kCLErrorLocationUnknown:
            //Probably temporary...
            errorString = @"Location data unavailable";
            //Do something else...
            break;
        default:
            errorString = @"An unknown error has occurred";
            break;
        }
    }

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:errorString delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
    [alert show];
    [alert release];
}

See the documentation on the CLError constants in the CLLocationManager class reference for more options.

@Dan,if locationServicesEnabled is false, then i have waited for long time, but delegate (locationManager:didFailWithError:) method is not called. what is the reason??

iphone - locationServicesEnabled test passes when they are disabled in...

iphone cllocationmanager
Rectangle 27 0

iOS 4.2 now allows one to determine if location services have been denied through the CLLocationManager +authorizationStatus method.

iphone - locationServicesEnabled test passes when they are disabled in...

iphone cllocationmanager
Rectangle 27 0

you can use the gps tracker class to get current location

public class GPSTracker extends Service implements LocationListener {

private final Context mContext;

// flag for GPS status
boolean isGPSEnabled = false;

// flag for network status
boolean isNetworkEnabled = false;

// flag for GPS status
boolean canGetLocation = false;

Location location; // location
double latitude; // latitude
double longitude; // longitude

// The minimum distance to change Updates in meters
private static final long MIN_DISTANCE_CHANGE_FOR_UPDATES = 1; // 10 meters

// The minimum time between updates in milliseconds
private static final long MIN_TIME_BW_UPDATES = (1000 * 60 * 1)/6; // 1 minute

// Declaring a Location Manager
protected LocationManager locationManager;

public GPSTracker(Context context) {
    this.mContext = context;
    getLocation();
}

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;
}

/**
 * Stop using GPS listener Calling this function will stop using GPS in your
 * app
 * */
public void stopUsingGPS() {
    if (locationManager != null) {
        locationManager.removeUpdates(GPSTracker.this);
    }
}

/**
 * Function to get latitude
 * */
public double getLatitude() {
    if (location != null) {
        latitude = location.getLatitude();
    }

    // return latitude
    return latitude;
}

/**
 * Function to get longitude
 * */
public double getLongitude() {
    if (location != null) {
        longitude = location.getLongitude();
    }

    // return longitude
    return longitude;
}

/**
 * Function to check GPS/wifi enabled
 * 
 * @return boolean
 * */
public boolean canGetLocation() {
    return this.canGetLocation;
}

/**
 * Function to show settings alert dialog On pressing Settings button will
 * lauch Settings Options
 * */
public void showSettingsAlert() {

    final AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
    builder.setMessage(
            "Your GPS seems to be disabled, do you want to enable it?")
            .setCancelable(true)
            .setPositiveButton("Yes", new DialogInterface.OnClickListener()

            {
            public void onClick(final DialogInterface dialog,
                        final int id) {
            Intent intent = new Intent(                            Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                    mContext.startActivity(intent);

                }
            });

    final AlertDialog alert = builder.create();

    alert.show();

}

@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;
}

}

make a object of gps tracker class

GPSTracker gps = new GPSTracker(youractivity.this);
 double _mylats = gps.getLatitude();
 double _mylongs = gps.getLongitude();

i used this class but it is giving me latitude & longitude as 0.0

did you declare permision in manifest?

java - Getting error in the location manager - Stack Overflow

java android locationmanager
Rectangle 27 0

So, if I click on cancel button instead of settings button in the alert and try to access the location once again... then what will happen?

You have to manually open setting app and click to yes. That means, user haven't interest to share his location and your app don't force user to share to his location. You have to think about this and you can manually check user authorization and switch to setting app from anywhere.

That is true.. But in this case I have to do it from 2nd time onwards. Isn't it? Because when the settings is disabled, iOS shows the pop-up for the first time. How to actually know that I have to show my customized alert now or handle it in other way?

I think you didn't get my question. Because iOS is handling the error condition for the first time, I do not have to show it for the first time. How do I know that this is not the first time.

gps - iOS: Can I disable the default alert pop-up with settings button...

ios gps wifi cllocationmanager
Rectangle 27 0

In your MainViewModel you need to check if they have allowed location services before you use the geocoordinatewatcher.

if(settings.LocationAllowed)
  {all your code for using location}

windows phone 7 - how to disable location services in my WP7 app - Sta...

windows-phone-7 geolocation
Rectangle 27 0

To my knowledge, you can't disable the location service on the simulator.

The approach that I normally use when using the location service is to build a simple wrapper class arround NSLocation tailored to the needs of my application.

In this wrapper, you could easily pretend that the service is not working in the simulator. For example, it could have a "isEnabled" method that returns false on the simulator with a compiler define like (#if TARGET_ IPHONE_SIMULATOR)

Disable location service in iPhone simulator? - Stack Overflow

iphone ios-simulator core-location
Rectangle 27 0

I ran into this same exact issue when using the region monitoring tools. It didn't matter what I did to disable the regions, the arrow remained. I did finally solve the issue by cleaning up the calls to locationManager. If you are closing your view and don't need the location manager, set it to nil and/or release it. If you are monitoring location in the background, it will stay up there, but if not, make sure you are cleaning up all your location monitoring.

It seems like it is a bug, but as I found out, it is not. Just requires a bit more cleanup.

Check all places where you have <CLLocationManagerDelegate> set up. They will be the places hanging on to your location monitoring.

iphone - Location services don't stop when application is terminated -...

iphone ios ipad core-location iphone-4
Rectangle 27 0

this code while give you all you want, is any kind of location service available or not ?, Provider, and error message if the is not location manager provider

public class LocationManager_check {

    LocationManager locationManager;
    Boolean locationServiceBoolean = false;
    int providerType = 0;
    static AlertDialog alert;

    public LocationManager_check(Context context) {
        locationManager = (LocationManager) context
                .getSystemService(Context.LOCATION_SERVICE);
        boolean gpsIsEnabled = locationManager
                .isProviderEnabled(LocationManager.GPS_PROVIDER);
        boolean networkIsEnabled = locationManager
                .isProviderEnabled(LocationManager.NETWORK_PROVIDER);

        if (networkIsEnabled == true && gpsIsEnabled == true) {
            locationServiceBoolean = true;
            providerType = 1;

        } else if (networkIsEnabled != true && gpsIsEnabled == true) {
            locationServiceBoolean = true;
            providerType = 2;

        } else if (networkIsEnabled == true && gpsIsEnabled != true) {
            locationServiceBoolean = true;
            providerType = 1;
        }

    }

    public Boolean isLocationServiceAvailable() {
        return locationServiceBoolean;
    }

    public int getProviderType() {
        return providerType;
    }

    public void createLocationServiceError(final Activity activityObj) {

        // show alert dialog if Internet is not connected
        AlertDialog.Builder builder = new AlertDialog.Builder(activityObj);

        builder.setMessage(
                "You need to activate location service to use this feature. Please turn on network or GPS mode in location settings")
                .setTitle("LostyFound")
                .setCancelable(false)
                .setPositiveButton("Settings",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                Intent intent = new Intent(
                                        Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                                activityObj.startActivity(intent);
                                alert.dismiss();
                            }
                        })
                .setNegativeButton("Cancel",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                alert.dismiss();
                            }
                        });
        alert = builder.create();
        alert.show();
    }

}
LocationManager_check locationManagerCheck = new LocationManager_check(
                    this);
            Location location = null;

if(locationManagerCheck .isLocationServiceAvailable){

    if (locationManagerCheck.getProviderType() == 1)
                location = locationManager
                        .getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
    else if (locationManagerCheck.getProviderType() == 2)
                location = locationManager
                        .getLastKnownLocation(LocationManager.GPS_PROVIDER);
}else{
    locationManagerCheck .createLocationServiceError(your_activity.this);
}

android - Show Popup when Location access is disable by user (Andorid ...

android google-maps maps
Rectangle 27 0

You can query the shared CLLocationManager instance if the location service is enabled. The correct way is to respect the users choice to disable location services.

But if you want to, just start the location service anyway and the user will be prompted to start it again. If the user opts in on the request locations will begin to be reported on your delegate as usual. If the user instead denies your request you will get a failure callback to the locationManager:didFailWithError: delegate method. The error will have an error code of kCLErrorDenied.

I would strongly discourage you from doing this, but you can try to start the service again if the user says no, and the user will be asked again. Most users will hate you for it though.

+1 the user should only decide whether they want to allow an app to use their location at one point, ive noticed a lot of apps ive used recently request permission regularly, even if it hasnt been allowed in the past, which im not a fan of

agree. if your app relies on location services for any significant functionality, the nice way to do this is to detect when location services are disabled and present passive UI in your app that notifies users and allows them to turn location services back on. If a user opts in you can then start location services which will prompt the user to enable.

Thanks for your feedback. I am with you and totally do not want to annoy my users be re-asking them to allow my application access to location services. But in this case, the user is tapping on the "get current location" button, so it seems appropriate to tell them that they need to turn this on. This is the same as in the Map application when the user taps on the "get current location" button. I am doing as you suggest, calling the start monitor method, but it does not re-prompt the user, I just get the kCLErrorDenied error.

This is incorrect. Once the location services authorization alert view is presented, users will never see it again. Ever. (Notwithstanding a phone reset.) Even an app delete and reinstall will not present it again. The only way a user can restore location service authorization is to go to the Settings app and re-enable it directly.

iphone - How to prompt user to turn on Location Services...again - Sta...

iphone ios cllocationmanager
Rectangle 27 0

This has been disabled in iOS 5. The best you could do is open preferences and tell the user to enable the location services

objective c - open setting screen to update location service in iphone...

iphone objective-c ios settings core-location
Rectangle 27 0

So, here is the answer. It's got something to do with the background location service. Apparently it was disabled for my application. Once I removed it from the Info.plist -- things started clicking again. Put it back -- the same exact issue. One would hope, the messages I got would be a bit more user friendly. Anyways, thanks for helping me.

ios - SpringBoard failed to launch application with error: 5 - Stack O...

ios
Rectangle 27 0

Location warnings are the requests made by apps (such as Camera, Compass, and Maps as well as location-based third-party apps) to use Location Services with those apps. An app will present a location warning the first time it needs to access Location Services data. Tapping OK will give that app permission to use Location Services as needed. Tapping Don't Allow will prevent an app from accessing Location Services data from then on.

You can't disable this location service alert. It is a system system generated one.

gps - iOS: Can I disable the default alert pop-up with settings button...

ios gps wifi cllocationmanager
Rectangle 27 0

There is no real good way to run a timer for the background services. The good news is the last location holds a timestamp you can compare last update to. It may not be approximate times, but you should be able to disable the location services after the last update after 30 minutes.

Yep, but unfortunately the only way to get the location is to trigger an even by moving to another location and not if the user is stationary

Yes, you are right. The user will still need to move before you will be able to disable location services. Thankfully, the significant change monitoring is very low power, so you shouldn't impact battery life all that much. Good luck.

objective c - CoreLocation on iOS to only monitor location changes in ...

objective-c ios
Rectangle 27 0

In Preferences you have two options to disable the location services. The first option is a global switch to disable the location service for all apps "[CLLocationManager locationServicesEnabled]". The second option let you disable the location service for some apps but not for all apps.

To check if its disabled globally and if its disabled for your app use following:

if([CLLocationManager locationServicesEnabled] && 
   [CLLocationManager authorizationStatus] != kCLAuthorizationStatusDenied)
{
...
}

I was struggeling a bit because just checking [CLLocationManager locationServicesEnabled] was not enough. Thanks!

deprecated... as of iOS 4

objective c - Checking for iOS Location Services - Stack Overflow

objective-c ios cllocationmanager
Rectangle 27 0

Once you disable location services for an app, location manager delegate methods will start showing error. So, on receiving error we can check if location services are enabled/disabled. And according to the result, we can ask the user to go to settings and turn on location services.

func locationManager(manager: CLLocationManager!, didFailWithError error: NSError!) {
    DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) {
            //check  location permissions
            self.checkLocationPermission()
        }
}
//check location services enabled or not

    func checkLocationPermission() {
        if CLLocationManager.locationServicesEnabled() {
            switch(CLLocationManager.authorizationStatus()) {
            case .notDetermined, .restricted, .denied:
                //open setting app when location services are disabled
            openSettingApp(message:NSLocalizedString("please.enable.location.services.to.continue.using.the.app", comment: ""))
            case .authorizedAlways, .authorizedWhenInUse:
                print("Access")
            }
        } else {
            print("Location services are not enabled")
            openSettingApp(message:NSLocalizedString("please.enable.location.services.to.continue.using.the.app", comment: ""))
        }
    }
//open location settings for app
func openSettingApp(message: String) {
    let alertController = UIAlertController (title: APP_NAME_TITLE, message:message , preferredStyle: .alert)

    let settingsAction = UIAlertAction(title: NSLocalizedString("settings", comment: ""), style: .default) { (_) -> Void in
        guard let settingsUrl = URL(string: UIApplicationOpenSettingsURLString) else {
            return
        }

        if UIApplication.shared.canOpenURL(settingsUrl) {
            UIApplication.shared.open(settingsUrl, options: [:], completionHandler: nil)
        }
    }
    alertController.addAction(settingsAction)
    let cancelAction = UIAlertAction(title: NSLocalizedString("cancel", comment: ""), style: .default, handler: nil)
    alertController.addAction(cancelAction)

    present(alertController, animated: true, completion: nil)
}

ios - How can I prompt the user to turn on location services after use...

ios core-location
Rectangle 27 0

You should probably take into account a few factors/points, most of which, you have. Anyway, you might find these helpful.

  • Your application settings toggle should only show when the location service is switched on on the device
  • GeoPositionStatus is just an Enum which contains the types of statuses.
  • StatusChanged is the event which is to be handled to check for changes in the device settings. See this.
  • You cannot change the device settings from the application.
  • Add event handlers before you call start on the watcher.

windows phone 7 - how to disable location services in my WP7 app - Sta...

windows-phone-7 geolocation
Rectangle 27 0

In Preferences you have two options to disable the location services. The first option is a global switch to disable the location service for all apps "[CLLocationManager locationServicesEnabled]". The second option let you disable the location service for some apps but not for all apps.

To check if its disabled globally and if its disabled for your app use following:

if([CLLocationManager locationServicesEnabled] && 
   [CLLocationManager authorizationStatus] != kCLAuthorizationStatusDenied)
{
...
}

I was struggeling a bit because just checking [CLLocationManager locationServicesEnabled] was not enough. Thanks!

deprecated... as of iOS 4

objective c - Checking for iOS Location Services - Stack Overflow

objective-c ios cllocationmanager
Rectangle 27 0

No, your code can not enable or disable the users Location Services. Nor should it be able to. You don't want Apps with the ability to make that decision for the user.

But i do want the App to make that decision for the user. This app wont be on the app store.

But you don't want other people to make that decision for you. If you are allowed to make an app that changes the settings then everyone is allowed to make an app that changes the settings.

Ok. I understand that it can't be done through code. But this App is for personal use only and never to be released on the app store. I understand your concern though.

objective c - How to disable location services for an iphone Simulator...

objective-c ios xcode ios-simulator