문제

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.

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top