【发布时间】:2011-06-03 00:49:12
【问题描述】:
我要做的就是从最后一个已知位置返回 long/lat 值,如果为 null,则拉取新坐标。
我对此很陌生,这就是我所拥有的:
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的输出是什么? -
它只是强制关闭,我什至无法运行它。
-
在这种情况下,您应该发布 LogCat 输出。