所有我想要做的是返回從最後一個知道位置的長/緯度值,如果這是null然後拉新的coords。Android位置管理器?
我很新的這一點,這是我有:
import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.TextView;
public class GPS extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
double longitude = location.getLongitude();
double latitude = location.getLatitude();
TextView output;
output = (TextView) findViewById(R.id.output);
output.append("\n\nLocations (starting with last known):");
Location location = locationManager.getLastKnownLocation(bestProvider);
printLocation(location);
}
}
你得到了什麼錯誤或者你的EditText輸出是什麼? – 2011-06-02 16:40:19
它只是強制關閉,我甚至不能運行它。 – Nick 2011-06-02 16:44:35
在這種情況下,您應該發佈LogCat輸出。 – 2011-06-02 16:53:38