2012-07-18 6 views
1

다음 코드를 사용하여 위도와 경도를 구합니다. 항상 네트워크 제공 업체에 의존하는 것이 좋습니까?네트워크에서 위도와 경도를 읽는 중

public static String getLatitudeLongitudeString() { 
    LocationManager lm = (LocationManager) GlobalApplication 
      .getAppContext().getSystemService(Context.LOCATION_SERVICE); 

    Location location = lm 
      .getLastKnownLocation(LocationManager.NETWORK_PROVIDER); 

    if (location == null) { 
     return ""; 
    } else { 
     Geocoder geocoder = new Geocoder(GlobalApplication.getAppContext()); 
     try { 
      List<Address> user = geocoder.getFromLocation(
        location.getLatitude(), location.getLongitude(), 1); 
      double lat = (double) user.get(0).getLatitude(); 
      double lng = (double) user.get(0).getLongitude(); 
      return lat + "," + lng; 
     } catch (Exception e) { 
      Trace.e("Failed to get latitude and longitude", e); 
      return ""; 
     } 
    } 
} 

답변

1

정직하게는 "의존". 그러나 리뷰 this article을 말하고 옵션의 가장 좋은 조합이 무엇인지 알아낼 것입니다. 패시브 공급자 (Froyo +)가 다른 앱에서 일부 GPS 업데이트를 수신하도록 할 수 있습니다 ... 또한 사용중인 앱에 따라 다릅니다. 매핑 앱이 있다면 GPS를 원하지만 "샌프란시스코에 있습니다"텍스트 만 입력하면 정확도가 떨어집니다.

+0

기사는 정말 통찰력이있었습니다. – ssk

+0

다행히 도울 수 있어요 :) –

0

사용 사례에 언급 된 Salil에 따라 다릅니다. 즉, 필요한 위치 세부 정보의 세부 수준까지 낮추게됩니다. 예를 들어 기상 응용 프로그램을 작성하려는 경우 대부분의 경우시를 알고 있으면 충분합니다. 사용자가 이동할 때지도를 업데이트하려는 경우 GPS 제공 업체가 제공하는 이상적인 위치가 필요합니다.

관련 문제