다음 코드를 사용하여 위도와 경도를 구합니다. 항상 네트워크 제공 업체에 의존하는 것이 좋습니까?네트워크에서 위도와 경도를 읽는 중
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 "";
}
}
}
기사는 정말 통찰력이있었습니다. – ssk
다행히 도울 수 있어요 :) –