String context = Context.LOCATION_SERVICE;
locationManager = (LocationManager) getSystemService(context);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE); // 정확도
criteria.setPowerRequirement(Criteria.POWER_LOW); // 전원 소비량
criteria.setAltitudeRequired(false); // 고도, 높이 값을 얻어 올지를 결정
criteria.setBearingRequired(false); // provider 기본 정보
criteria.setSpeedRequired(false); // 속도
criteria.setCostAllowed(true);
if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
{
String provider = locationManager.getBestProvider(criteria, true);
lastKnownLocation = locationManager.getLastKnownLocation(provider);
if(lastKnownLocation == null)
{
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
lastKnownLocation = locationManager.getLastKnownLocation(provider);
}
if(lastKnownLocation == null)
{
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(R.string.gps_fail).setCancelable(false)
.setPositiveButton(R.string.gps_yes, new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id)
{
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
}
else
{
Latitude = lastKnownLocation.getLatitude();
Longitude = lastKnownLocation.getLongitude();
}
// lastKnownLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
}
else if(locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER))
{
String provider = locationManager.getBestProvider(criteria, true);
lastKnownLocation = locationManager.getLastKnownLocation(provider);
if(lastKnownLocation == null)
{
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
lastKnownLocation = locationManager.getLastKnownLocation(provider);
}
if(lastKnownLocation == null)
{
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(R.string.gps_fail).setCancelable(false)
.setPositiveButton(R.string.gps_yes, new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id)
{
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
}
else
{
Latitude = lastKnownLocation.getLatitude();
Longitude = lastKnownLocation.getLongitude();
}
}
이부분에서 네트워크쪽에서는 null값이 들어오지 않지만
gps부분에서는 공기계 gps를 잡았을경우에만 provider에 null 값이 들어옵니다 그래서 lastknownLocation 에서 null값이 들어와 밑에 if 문에서 null일 경우 업데이트를 시켜서 위도 경도 값을 가져오려고 하였는데 결국에는 null 들어와 다이얼로그가 실행되더군요 ㅠㅠ gps부분에서만 null값이고 와이파이나 3g/4g 일경우에는 정상적으로 실행이 되는데
어디가 잘못된건지 감을 못잡겠네요 ㅠㅠ 도와주세요 ㅠ 조언좀부탁드릴꼐요 ㅠ