在我的應用程序中,需要取當前的位置信息,我使用下面的代碼;並稱之爲buttonclick,但它不能在設備和模擬器中工作,如果任何人有任何想法請幫助。GPS位置信息問題
private void getLocationServices(){
Thread geoThread=new Thread(){
public void run(){
try{
Criteria myCriteria = new Criteria();
myCriteria.setCostAllowed(false);
try{
LocationProvider myLocationProvider = LocationProvider.getInstance(myCriteria);
try{
locationaddress=new AddressInfo();
Location myLocation = myLocationProvider.getLocation(300);
_lattitude = myLocation.getQualifiedCoordinates().getLatitude();
_longitude = myLocation.getQualifiedCoordinates().getLongitude();
int intLatitude = (int) _lattitude * 100000;
int intLongitude = (int) _longitude * 100000;
try{
Landmark[] results= Locator.reverseGeocode(intLatitude, intLongitude, Locator.ADDRESS);
if (results != null && results.length > 0) {
locationaddress=results[0].getAddressInfo();
lblLoc.setText(locationaddress.getField(AddressInfo.CITY));
}
}catch (Exception e) {
// TODO: handle exception
}
}catch (Exception e) {
// TODO: handle exception
}
}catch (Exception e) {
// TODO: handle exception
}
}catch (Exception e) {
// TODO: handle exception
}
}
};
geoThread.start();
}
你有它不工作更多的細節?例如,你是否遇到異常?如果是這樣,在哪一行?或者你的結果與預期不同?需要一些關於什麼不工作的更多細節。 – 2011-02-08 16:59:04