2015-02-10 98 views
0

我想做一個簡單的android應用程序來確定當前位置的GPS,但是當我在我的手機上運行應用程序它只是給我的準確性,而沒有給出真正的座標這裏是我的代碼位置管理器不工作

@Override 
protected void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    v1 = (TextView) findViewById(R.id.textView1); 
    v2 = (TextView) findViewById(R.id.textView1); 
    v3 = (TextView) findViewById(R.id.textView1); 

    int GpsUpdateInterval = 60 * 1000; 
    int GpsUpdateRadius = 15; 

    LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); 

    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 
      GpsUpdateInterval, GpsUpdateRadius, new LocationListener() { 

     @Override 
       public void onStatusChanged(String provider, int status, 
         Bundle exras) { 
       } 

       @Override 
       public void onProviderEnabled(String provider) { 
       } 

       @Override 
       public void onProviderDisabled(String provider) { 
       } 

       @Override 
       public void onLocationChanged(Location location) { 
        // this function trigger when a new location founded 
        v1.setText("Lat " 
          + String.valueOf(location.getLatitude())); 
        v2.setText("Lng " 
          + String.valueOf(location.getLongitude())); 
        v3.setText("Accurcy " 
          + String.valueOf(location.getAccuracy())); 

       } 
      }); 

} 

回答

1
v1 = (TextView) findViewById(R.id.textView1); 
v2 = (TextView) findViewById(R.id.textView1); 
v3 = (TextView) findViewById(R.id.textView1); 

你有不良視圖綁定;)

+1

啊哈謝謝你,但你可以請檢查代碼的其餘部分,如果它的正確與否 – Suhaybovic 2015-02-10 14:22:49

+0

是的,是完全沒有 – webo80 2015-02-10 14:24:34

+0

非常感謝你 – Suhaybovic 2015-02-10 14:26:38