0

I want my LocationManager to attempt to get Fine_Location first, and then if not available get Coarse_Location. Can this type of hierarchy be set up for the Criteria Accuracy property?

const string context = LocationService;
LocationManager locationManager = (LocationManager)GetSystemService(context);
Criteria criteria = new Criteria() { Accuracy = Accuracy.Fine | Accuracy.Coarse };
string provider = locationManager.GetBestProvider(criteria, true);
wislon
  • 723
  • 5
  • 21
jmease
  • 2,507
  • 5
  • 49
  • 89

2 Answers2

1

Taken from the documentation for the GetBestProvider() method:

Returns the name of the provider that best meets the given criteria. Only providers that are permitted to be accessed by the calling activity will be returned. If several providers meet the criteria, the one with the best accuracy is returned.

This sounds like the behavior you're looking for.

Greg Shackles
  • 10,009
  • 2
  • 29
  • 35
  • I apologize if I was unclear. When I have the Accuracy set to Fine but am indoors where I have network coverage but no GPS coverage, the location returns null. But then when I set it to Course, it returns a value based on network coverage. I want the location to be as accurate as possible, but I don't want it to return null if it can't get a GPS signal. – jmease Apr 06 '12 at 16:31
0

I want the location to be as accurate as possible, but I don't want it to return null if it can't get a GPS signal

Then you have to register for both providers - provider = LocationManager.GetBestProvider(criteria, true); will return the best available provider - it won't check to see if this provider can actually get a fix. See here and here for registering with both providers

Community
  • 1
  • 1
Mr_and_Mrs_D
  • 32,208
  • 39
  • 178
  • 361