Как исправить 'java.lang.IllegalArgumentException: Неправильное географическое местоположение: -118.2541117, 33.985805' - PullRequest
0 голосов
/ 05 января 2019

Я устанавливаю текущее местоположение в моем приложении. Но оно упало

на com.example.webforest.quickaidlikeuber2nd.CustomerMapActivity.getDriversAround (CustomerMapActivity.java:577)

 boolean getDriversAroundStarted = false;
List<Marker> markers = new ArrayList<Marker>();
private void getDriversAround(){
    getDriversAroundStarted = true;
    DatabaseReference driverLocation = FirebaseDatabase.getInstance().getReference().child("driversAvailable");

    GeoFire geoFire = new GeoFire(driverLocation);
    GeoQuery geoQuery = geoFire.queryAtLocation(new GeoLocation(mLastLocation.getLongitude(), mLastLocation.getLatitude()), 999999999);

на com.example.webforest.quickaidlikeuber2nd.CustomerMapActivity.access $ 2300 (CustomerMapActivity.java:76)

public class CustomerMapActivity extends FragmentActivity implements OnMapReadyCallback {

private GoogleMap mMap;
Location mLastLocation;
LocationRequest mLocationRequest;

private FusedLocationProviderClient mFusedLocationClient;

private Button mLogout, mRequest, mSettings, mHistory;

private Boolean requestBol = false;

private Marker pickupMarker;

private LatLng pickupLocation;

private SupportMapFragment mapFragment;

private String destination, requestService;

private LatLng destinationLatLng;

private LinearLayout mDriverInfo;

private ImageView mDriverProfileImage;

private TextView mDriverName, mDriverPhone, mDriverCar;

private RadioGroup mRadioGroup;

private RatingBar mRatingBar;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_customer_map);
    // Obtain the SupportMapFragment and get notified when the map is ready to be used.

    mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);

    mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);

    destinationLatLng = new LatLng(0.0, 0.0);

    mDriverInfo = (LinearLayout) findViewById(R.id.driverInfo);

    mDriverProfileImage = (ImageView) findViewById(R.id.driverProfileImage);

    mDriverName = (TextView) findViewById(R.id.driverName);
    mDriverPhone = (TextView) findViewById(R.id.driverPhone);
    mDriverCar = (TextView) findViewById(R.id.driverCar);

    mRatingBar = (RatingBar) findViewById(R.id.ratingBar);

    mRadioGroup = (RadioGroup) findViewById(R.id.radioGroup);
    mRadioGroup.check(R.id.UberX);

    mLogout = (Button) findViewById(R.id.logout);
    mRequest = (Button) findViewById(R.id.request);
    mSettings = (Button) findViewById(R.id.settings);
    mHistory = (Button) findViewById(R.id.history);

    mLogout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            FirebaseAuth.getInstance().signOut();
            Intent intent = new Intent(CustomerMapActivity.this, MainActivity.class);
            startActivity(intent);
            finish();
            return;
        }
    });

    mRequest.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            if (requestBol) {
                endRide();


            } else {
                int selectId = mRadioGroup.getCheckedRadioButtonId();

                final RadioButton radioButton = (RadioButton) findViewById(selectId);

                if (radioButton.getText() == null) {
                    return;
                }

                requestService = radioButton.getText().toString();

                requestBol = true;

                String userId = FirebaseAuth.getInstance().getCurrentUser().getUid();

                DatabaseReference ref = FirebaseDatabase.getInstance().getReference("customerRequest");
                GeoFire geoFire = new GeoFire(ref);
                geoFire.setLocation(userId, new GeoLocation(mLastLocation.getLatitude(), mLastLocation.getLongitude()));

                pickupLocation = new LatLng(mLastLocation.getLatitude(), mLastLocation.getLongitude());
                pickupMarker = mMap.addMarker(new MarkerOptions().position(pickupLocation).title("Pickup Here").icon(BitmapDescriptorFactory.fromResource(R.mipmap.ic_pickup)));

                mRequest.setText("Getting your Driver....");

                getClosestDriver();
            }
        }
    });
    mSettings.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(CustomerMapActivity.this, CustomerSettingsActivity.class);
            startActivity(intent);
            return;
        }
    });

    mHistory.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(CustomerMapActivity.this, HistoryActivity.class);
            intent.putExtra("customerOrDriver", "Customers");
            startActivity(intent);
            return;
        }
    });

    PlaceAutocompleteFragment autocompleteFragment = (PlaceAutocompleteFragment)
            getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);

    autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
        @Override
        public void onPlaceSelected(Place place) {
            // TODO: Get info about the selected place.
            destination = place.getName().toString();
            destinationLatLng = place.getLatLng();
        }

        @Override
        public void onError(Status status) {
            // TODO: Handle the error.
        }
    });


}

сказано в com.example.webforest.quickaidlikeuber2nd.CustomerMapActivity $ 10.onLocationResult (CustomerMapActivity.java:512)

 LocationCallback mLocationCallback = new LocationCallback(){
    @Override
    public void onLocationResult(LocationResult locationResult) {
        for(Location location : locationResult.getLocations()){
            if(getApplicationContext()!=null){
                mLastLocation = location;

                LatLng latLng = new LatLng(location.getLatitude(),location.getLongitude());

                //mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
                //mMap.animateCamera(CameraUpdateFactory.zoomTo(11));
                if(!getDriversAroundStarted)
                    getDriversAround();
            }
        }
    }
};

После этой ошибки, которую я получаю

java.lang.IllegalArgumentException: Not a valid geo location: -118.2541117, 33.985805
    at com.firebase.geofire.GeoLocation.<init>(GeoLocation.java:51)
    at com.example.webforest.quickaidlikeuber2nd.CustomerMapActivity.getDriversAround(CustomerMapActivity.java:577)
    at com.example.webforest.quickaidlikeuber2nd.CustomerMapActivity.access$2300(CustomerMapActivity.java:76)
    at com.example.webforest.quickaidlikeuber2nd.CustomerMapActivity$10.onLocationResult(CustomerMapActivity.java:512)
    at com.google.android.gms.internal.location.zzau.notifyListener(Unknown Source)
    at com.google.android.gms.common.api.internal.ListenerHolder.notifyListenerInternal(Unknown Source)
    at com.google.android.gms.common.api.internal.ListenerHolder$zaa.handleMessage(Unknown Source)

Ответы [ 2 ]

0 голосов
/ 08 января 2019

Похоже, у вас широта и долгота в неправильном порядке.

Сообщение об ошибке Not a valid geo location: -118.2541117, 33.985805 показывает широту, за которой следует longitutude. Широта -118 градусов не имеет смысла. Значения широты должны находиться в диапазоне от -90 до +90 градусов.


Скажите, пожалуйста, как можно решить эту проблему.

Тщательно изучите ваш код, чтобы увидеть, где широта и долгота были переключены.

Похоже, что может быть здесь:

  GeoQuery geoQuery = geoFire.queryAtLocation(
          new GeoLocation(mLastLocation.getLongitude(),
                          mLastLocation.getLatitude()), 999999999);

Вы можете проверить это с помощью отладчика.

0 голосов
/ 05 января 2019

Пожалуйста, посмотрите его исходные коды :

if (!GeoLocation.coordinatesValid(latitude, longitude)) {
    throw new IllegalArgumentException("Not a valid geo location: " + latitude + ", " + longitude);
}

public static boolean coordinatesValid(double latitude, double longitude) {
    return latitude >= -90 && latitude <= 90 && longitude >= -180 && longitude <= 180;
}

Примечание -118.2541117 находится вне допустимого диапазона.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...