Handling no location

Put problem concerning MapActivities, MapViews, Overlays and GPS in this forum.

Handling no location

Postby iaindownie » Thu Feb 24, 2011 10:50 am

Hi

in my app that uses MapView, I am using the following to detect for GPS switched on or not:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
  2.         Toast.makeText(this, "GPS is Enabled in your device",
  3.                         Toast.LENGTH_SHORT).show();
  4. } else {
  5.         showGPSDisabledAlertToUser();
  6. }
  7.  
Parsed in 0.030 seconds, using GeSHi 1.0.8.4

but my app is still Force Closing if the Use Wireless Networks is switched off, since it can't seem to find a location fix. Does anyone have any best practice advice or examples for the best way to:
  • Check for GPS, dialog box to switch on (above)
  • On not switch on GPS, check for Wireless, dialog box to switch on
  • On not switch on Wireless, finish() app completely?
Thanks
Iain
User avatar
iaindownie
Experienced Developer
Experienced Developer
 
Posts: 84
Joined: Mon Dec 29, 2008 4:08 pm
Location: Thetford, Norfolk, UK

Top

Re: Handling no location

Postby iaindownie » Thu Feb 24, 2011 12:14 pm

Think I have it sorted:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. if(!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) &&
  2.                 !locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)){
  3.         showGPSDisabledAlertToUser("LOCATION");
  4. }else{
  5.         if(!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){
  6.                 showGPSDisabledAlertToUser("GPS");
  7.         }else{
  8.                 Toast.makeText(this, "GPS/Wireless is Enabled in your device",
  9.                                 Toast.LENGTH_SHORT).show();
  10.         }
  11. }
  12.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
User avatar
iaindownie
Experienced Developer
Experienced Developer
 
Posts: 84
Joined: Mon Dec 29, 2008 4:08 pm
Location: Thetford, Norfolk, UK

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 2 guests