0

I am trying to get current location using GPS,Cellular Network or WiFi.I am giving criteria to choose best provider. But It is always showing GPS is best provider. It is ok when i am outside and GPS signal is strong but it is not true when i am indoor or GPS signal is poor. The criteria are

  Criteria criteria  = new Criteria();
  criteria.setAccuracy(Criteria.ACCURACY_FINE);
  criteria.setAltitudeRequired(false);
  criteria.setBearingRequired(false);
  criteria.setCostAllowed(true);
  criteria.setPowerRequirement(Criteria.POWER_LOW);
  WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
  wifi.setWifiEnabled(true);
  String provider = lm.getBestProvider(criteria, true);

What is the solution? Any help please.

4

1 に答える 1

0

Setting accuracy criteria to Criteria.ACCURACY_FINE will always give you GPS_PROVIDER if available in your device. On the other hand setting Criteria.ACCURACY_COARSE gives you NETWORK_PROVIDER if available. It's good practice to start both and use NETWORK_PROVIDER first as it may take few minutes to get a fix from GPS.

See android-protips-location for the location best-practices for reducing latency and battery consumption.

These also may help:

Location Strategies

Android Protips: Advanced Topics for Expert Android App Developers

于 2012-07-21T14:27:00.603 に答える