我正在尝试获取用户的纬度和经度。我创建了一个基本应用程序。当我运行它并提供纬度和经度时,它会在模拟器中重新启动操作系统。我怎样才能解决这个问题?
这是我的代码
public class MGeolocationActivity extends Activity {
TextView tvLat;
TextView tvLong;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tvLat = (TextView)findViewById(R.id.tvLat);
tvLong = (TextView)findViewById(R.id.tvLong);
LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
LocationListener ll = new myLocationListener();
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, ll);
}
class myLocationListener implements LocationListener {
@Override
public void onLocationChanged(Location location) {
if(location != null) {
double pLong = location.getLongitude();
double pLat = location.getLatitude();
tvLat.setText(Double.toString(pLat));
tvLong.setText(Double.toString(pLong));
}
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
}
}