【发布时间】:2016-05-13 22:23:42
【问题描述】:
在我的代码中,当布局加载时,它会获取 gps 坐标。这是我的示例代码。如果 GPS 关闭,它工作正常。如果我打开 gps,它不会加载 gps 坐标。当他打开 GPS 时,我需要获取用户 gps 坐标。所以有什么问题。我需要改变的地方。对不起我的英语。
dialog = new ProgressDialog(FXPage.this);
dialog.show();
dialog.setMessage("Getting Coordinates");
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
if (locationManager
.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, 100000000,
1, this);
} else if (locationManager
.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER, 100000000,
1, this);
}
else {
dialog.dismiss();
Toast.makeText(getApplicationContext(), "Enable Location", Toast.LENGTH_LONG).show();
}
protected void refresh() {
super.onResume();
this.recreate();
}
@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
dialog.show();
latitude = location.getLatitude();
longitude =location.getLongitude();
if (latitude != 0 && longitude != 0){
edittext6.setText(location.getLatitude()+","+location.getLongitude());
dialog.dismiss();
}
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
【问题讨论】:
标签: android gps android-location