如何修复'java.lang.IllegalArgumentException:不是有效的地理位置:-118.2541117,33.985805'

时间:2019-01-05 07:20:56

标签: android dictionary geolocation

我正在应用程序中设置一个当前位置。但是它崩溃了

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

val rawJson: String = """xxx{"a": "x", "b": "y", "c": "z"}""" // invalid JSON
val rawJson: String = """[1,2,3]""" // not a JSON object
val rawJson: String = """{"a": 1, "b": "y", "c": "z"}""" // not all values are string

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

async def get_cells(websocket):
    async for message in websocket:
        ...

async def get_shaded_area(websocket):
    async for message in websocket:
        ...

async def router(websocket, path):
    if path == "/":
        await get_cells(websocket, path)
    elif path == "/shade-area":
        await get_shaded_area(websocket, path)

asyncio.get_event_loop().run_until_complete(
    websockets.serve(router, 'localhost', 8765))

asyncio.get_event_loop().run_forever()

在com.example.webforest.quickaidlikeuber2nd.CustomerMapActivity $ 10.onLocationResult(CustomerMapActivity.java:512)中说

 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);

出现此错误之后

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.
        }
    });


}

2 个答案:

答案 0 :(得分:1)

请查看其source codes

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不在允许的范围内。

答案 1 :(得分:1)

看来您的经纬度顺序错误。

错误消息Not a valid geo location: -118.2541117, 33.985805显示纬度,后跟经度。 -118度的纬度没有意义。纬度值必须在-90到+90度之间。


  

请告诉我如何解决这个问题。

仔细检查您的代码,看看在哪里改变了纬度和经度。

看起来可能可能在这里:

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

您可以使用调试器进行验证。