我已经将我的问题挑出到几行代码中
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,我的应用程序会崩溃
但是如果我手动给它一个位置,它就可以正常工作
我不知道目前有什么问题