"gps" or "network"

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

"gps" or "network"

Postby rd42 » Fri Apr 02, 2010 4:30 pm

I have an app that I would like to use gps if available and network if gps is disabled. My understanding was that
Code: Select all
requestLocationUpdates("LocationManager.GPS_PROVIDER", 0, 0,onLocationChange);


did just that.

When I use
Code: Select all
requestLocationUpdates("network", 0, 0,onLocationChange);


it reads from the network if gps is disabled if I use "LocationManager.GPS_PROVIDER" it will only work if the gps is enabled on the phone.

Does any body know how to default to network if the gps is not enabled?

Thanks,
rd42
User avatar
rd42
Junior Developer
Junior Developer
 
Posts: 22
Joined: Thu Apr 01, 2010 5:12 pm

Top

Postby rd42 » Fri Apr 02, 2010 4:58 pm

My fix for now.

Code: Select all
   
   LocationManager locm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
   //Check if GPS is enabled and choose network if it isn't
    if ( !locm.isProviderEnabled( LocationManager.GPS_PROVIDER ) ) {
       locm.requestLocationUpdates("network", 0, 0,onLocationChange);
    } else {
       locm.requestLocationUpdates("gps", 0, 0,onLocationChange);   
    }
User avatar
rd42
Junior Developer
Junior Developer
 
Posts: 22
Joined: Thu Apr 01, 2010 5:12 pm

Postby nicholas.hauschild » Mon Apr 05, 2010 5:34 am

Hello rd42,

Here is the Javadoc for LocationManager

I believe there is a method on there, getBestProvider(...), which you can use to resolve your issue.

Good Luck!!!
nicholas.hauschild
Master Developer
Master Developer
 
Posts: 310
Joined: Fri Dec 04, 2009 4:50 am

Postby rd42 » Mon Apr 05, 2010 1:42 pm

Excellent, thanks! Just what I was looking for.

rd42
User avatar
rd42
Junior Developer
Junior Developer
 
Posts: 22
Joined: Thu Apr 01, 2010 5:12 pm

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 3 guests