2011-01-21 82 views
1

我正在按照教程來獲取我的當前位置。我寫了教程所說的內容,但我只是不明白我的經驗。我正在使用無線連接。我試過了:
geo fix -77.036519 38.896143
仍然沒有獲得緯度/經度。我的代碼如下;當前位置在Android模擬器中不工作

import java.util.List; 
import android.app.Activity; 
import android.content.Context; 
import android.location.Location; 
import android.location.LocationManager; 
import android.location.LocationListener; 
import android.os.Bundle; 
import android.widget.TextView; 

public class TestProviderController extends Activity { 
LocationManager locationManager; 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     String location_context=Context.LOCATION_SERVICE; 
     locationManager=(LocationManager)getSystemService(location_context); 
     testProvider(); 
    } 
    public void testProvider(){ 
    TextView tv = (TextView)findViewById(R.id.myTextView); 
    StringBuilder sb = new StringBuilder("Enabled Providers:"); 

    List<String> providers = locationManager.getProviders(true); 

    for (String provider : providers) { 

    locationManager.requestLocationUpdates(provider, 1000, 0, 
    new LocationListener() { 
    public void onLocationChanged(Location location) {} 
    public void onProviderDisabled(String provider){} 

    public void onProviderEnabled(String provider){} 
    public void onStatusChanged(String provider, int status, 
    Bundle extras){} 
    }); 
    sb.append("\n").append(provider).append(":"); 
    Location location = locationManager.getLastKnownLocation(provider); 
    if (location != null) { 
    double lat = location.getLatitude(); 
    double lng = location.getLongitude(); 
    sb.append(lat).append(",").append(lng); 
    } else { 
    sb.append("No Location"); 
    } 
    } 
    tv.setText(sb); 
    } 
} 

任何人都可以幫忙解決問題嗎?

+0

http://stackoverflow.com/editing-help – 2011-01-21 22:24:03

回答

0

它顯然可以花一點時間來獲取座標 - 這裏有一個類似question

+0

Hi..I試圖ü建議的鏈接,仍然沒有一個鏈接得到我的經/緯度。但如你所說可能需要一些時間,需要多長時間才能獲得經緯度? – kandroid 2011-01-22 13:48:34

相關問題