2012-08-16 84 views
0

我有一個文本視圖來顯示我的經度和緯度,現在的問題是我總是得到這對夫婦(32,35)(這是我認爲的某個海洋中的某個地方),我甚至去過出去散步,給全球定位系統一個機會,但我什麼都沒有。Android獲取靜態錯誤的位置

我想看看它是否與我的手機或手機中的GPS有關,所以我繼續打開Waze應用程序,看到它實際上工作。

可能是什麼問題?

這裏是我的簡單的代碼片段:

public class Main extends Activity implements LocationListener { 
    private LocationManager manager; 
    private TextView tv; 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     tv = (TextView) findViewById(R.id.textView1); 
     tv.setText("Hello There"); 
     manager = (LocationManager) this.getSystemService(LOCATION_SERVICE); 
     manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); 

    } 

    @Override 
    public void onLocationChanged(Location location) { 
     tv.setText((int)location.getLatitude()+ ","+ (int)location.getLongitude()); 
    } 
... 
} 
+0

權限被添加? – 2012-08-16 10:20:05

+2

@MMohsinNaeem:他說他在谷歌地圖中獲得了valus(32,35) – MAC 2012-08-16 10:21:28

回答

1

嘗試這種

tv.setText(location.getLatitude()+ ","+location.getLongitude()); 

代替

tv.setText((int)location.getLatitude()+ ","+ (int)location.getLongitude()); 
      ^^^        ^^^ 

,因爲你正在轉換latitudelongitudeint並在你可能會遇到很小的變化。

32.110 35.500 you will get (32,35) 
32.120 35.540 you will get (32,35) 
32.180 35.580 you will get (32,35) 
32.200 35.900 you will get (32,35) 
32.290 35.880 you will get (32,35) 
    ^^^ ^^^ 
+0

32,35是在太平洋某處:\ – 2012-08-16 10:51:10