我使用下面的代碼來獲取經度和緯度。總是依賴網絡服務提供商很好嗎?從網絡讀取經度和緯度
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 2012-07-21 22:08:17
很高興我能幫忙:) – 2012-07-22 18:28:23