안드로이드 3종 GSM 핸드폰 포지셔닝 기술 분석

 
// LocationManager
LocationManager loctionManager;
// , LocationManager
loctionManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
방식1:
 
// GPS
String providerGPS = LocationManager.GPS_PROVIDER;
Location location = loctionManager.getLastKnownLocation(providerGPS);
방식 2:
 
//
String providerNetwork = LocationManager.NETWORK_PROVIDER;
Location location = loctionManager.getLastKnownLocation(providerNetwork);
방식 3:
 
// , ,
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);//
criteria.setAltitudeRequired(false);//
criteria.setBearingRequired(false);//
criteria.setCostAllowed(true);//
criteria.setPowerRequirement(Criteria.POWER_LOW);//
// ,
String provider = loctionManager.getBestProvider(criteria, true);
//
Location location = loctionManager.getLastKnownLocation(provider);

처리:
 
// EditText
updateWithNewLocation(location);
// ,2 , 10
loctionManager.requestLocationUpdates(provider, 1000, 1, locationListener);
감청기 및 표시:
 
//
private final LocationListener locationListener = new LocationListener() {
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onProviderDisabled(String provider) {
}
//
@Override
public void onLocationChanged(Location location) {
// location TextView
updateWithNewLocation(location);
}
};
private void updateWithNewLocation(Location location) {
if (location != null) {
double lat = location.getLatitude();
double lng = location.getLongitude();
latStr = format.format(lat);
lonStr = format.format(lng);
txtLat.setText(latStr);
txtLon.setText(lonStr);
} else {
txtLat.setText("");
txtLon.setText("");
}
}

좋은 웹페이지 즐겨찾기