2010-08-13 52 views
0

我用this教程來編寫我的應用程序。我使用DDMS位置管理器虛擬地更改我的位置。GPS:loc.getLatitude /經度始終爲0.0

不幸的是,我總是得到一個位置爲0.0長和緯。即使我稍後在prog中使用locationchanged-method切換它,我也會得到0.0。

代碼是這樣的:

@Override 
public void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    //---use the LocationManager class to obtain GPS locations--- 
    lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);  
    locationListener = new MyLocationListener(); 
    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener); 

    Location lastLoc = lm.getLastKnownLocation("gps"); 

    curLocation = "Standort: \nLatitude: " + lastLoc.getLatitude() + "\nLongitude: " + lastLoc.getLongitude(); 

    upperText = (TextView) findViewById(R.id.TextView01); 
    upperText.setText(curLocation); 
} 

@Override 
    public void onLocationChanged(Location loc) 
    { 
     if (loc != null) { 
      Toast.makeText(getBaseContext(), 
       "Location changed : Lat: " + loc.getLatitude() + 
       " Lng: " + loc.getLongitude(), 
       Toast.LENGTH_SHORT).show(); 
     } 

     if (loc != null) 
     { 
      upperText.setText(curLocation + "\n\nStandort: \nLatitude: " + loc.getLatitude() 
        + "\nLongitude: " + loc.getLongitude()); 
     } 
    } 

數據不完整,但我不知道是什麼...:/

我會,如果有人真的很高興可以幫助=)!

+0

你傳遞緯度GPS信號閃爍, /經度:48.020203或48,020203? – Sephy 2010-08-13 09:48:51

+0

在DDMS中,我寫了48.020203。所以一點。我使用了位置管理器的默認輸入,它也沒有工作。 – Vivi 2010-08-13 10:00:05

回答

0

去地圖默認的應用程序,允許用戶允許的經度和緯度的選項。在我們的應用程序時,當它停止,我們會得到緯度和longitude.It工作對我來說