我已经将我的问题缩小到了几行代码。
lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000L, 5.0f, this);
lat = location.getLatitude();
lng = location.getLongitude();
//lat = new Double(40.431682);
//lng = new Double(-74.2021819);
pLocation = new GeoPoint((int)(lat * 1000000), (int)(lng * 1000000));
如果你想知道的话,我会提供我的onLocationChanged函数
public void onLocationChanged(Location location) {
if (location != null) {
lat = location.getLatitude();
lng = location.getLongitude();
pLocation = new GeoPoint((int)(lat * 1000000), (int)(lng * 1000000));
}
}
如果我尝试获取LastKnownLocation,则我的应用程序会崩溃。
但是,如果我手动提供位置信息,它就可以正常工作。
目前我不知道出了什么问题。