은 내가 다음 코드이 적응하려고 ...하지만 난 내가 isBetterLocation(Location location, Location currentBestLocation)
location 및 currentBestLocation은 어디에서 제공됩니까? 안드로이드 개발자 가이드 (얻기 사용자 위치)에
Example.class
private LocationManager locman;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String context = Context.LOCATION_SERVICE;
locman = (LocationManager)getSystemService(context);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setPowerRequirement(Criteria.POWER_LOW);
String provider = locman.getBestProvider(criteria, true);
locman.requestLocationUpdates(
provider,MIN_TIME, MIN_DISTANCE, locationListener);
}
private LocationListener locationListener = new LocationListener(){
@Override
public void onLocationChanged(Location location) {
// What should i pass as first and second parameter in this method
if(isBetterLocation(location1,location2)){
// isBetterLocation = true > do updateLocation
updateLocation(location);
}
}
@Override
public void onProviderDisabled(String provider) {}
@Override
public void onProviderEnabled(String provider) {}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {}
};
protected boolean isBetterLocation(Location location, Location currentBestLocation) {
if (currentBestLocation == null) {
// A new location is always better than no location
return true;
}
//Brief ... See code in Android Dev Guid "Obtaining User Location"
}
내 코드에 예제를 표시 하시겠습니까? 여러 청취자에 대해. 나는 여전히 어떤 위치 값을 메소드 isBetterlocation()에 전달해야하는지와 currentBestLocation을 설정할 때를 혼동했다. –
코드 예제를 위해 편집했다. – MrJre
고맙습니다. –