我遇到問題。我想在android應用程序中查找當前位置的經度和緯度。當我用手機穩定時,我只需要它。找到當前位置的經緯度
我的代碼是:
LocationManager locationManager;
locationManager = (LocationManager)getSystemService
(Context.LOCATION_SERVICE);
Location location = locationManager.getLastKnownLocation
(LocationManager.GPS_PROVIDER);
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,0,0,(LocationListener) this);
updateWithNewLocation(location);
}
private void updateWithNewLocation(Location location) {
TextView myLocationText = (TextView)findViewById(R.id.myLocationText);
String latLongString;
if (location != null) {
double lat = location.getLatitude();
double lng = location.getLongitude();
latLongString = "Lat:" + lat + "\nLong:" + lng;
} else {
latLongString = "No location found";
}
myLocationText.setText("Your Current Position is:\n" +
latLongString);
}
在模擬器中運行它之後我總是覺得「找不到位置」。爲什麼這樣呢?
你能告訴我們你的代碼,所以我們可以看到,爲什麼它不工作?這個問題已經在StackOverflow上問過很多次了。做一個搜索,你可能已經找到了你的問題的答案。 – 2010-02-12 09:10:34
你不會從你的模擬器獲得GPS。試試真正的設備。 – Dhruvisha 2012-05-04 09:19:04