如何修复“java.lang.IllegalArgumentException:不是有效的地理位置:-118.2541117、33.985805”
How to fix ' java.lang.IllegalArgumentException: Not a valid geo location: -118.2541117, 33.985805'
我正在我的 application.But 中设置当前位置它崩溃了
在 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.access00(CustomerMapActivity.java:76)
at com.example.webforest.quickaidlikeuber2nd.CustomerMapActivity.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)
请看它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
不在允许范围内。
看来你输入的纬度和经度顺序有误。
错误消息Not a valid geo location: -118.2541117, 33.985805
显示纬度后跟经度。 -118 度的纬度毫无意义。纬度值必须在 -90 到 +90 度范围内。
Please tell me how can solve this.
仔细检查你的代码,看看纬度和经度在哪里被调换了。
看起来可能在这里:
GeoQuery geoQuery = geoFire.queryAtLocation(
new GeoLocation(mLastLocation.getLongitude(),
mLastLocation.getLatitude()), 999999999);
您可以使用调试器进行验证。
我正在我的 application.But 中设置当前位置它崩溃了
在 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.access00(CustomerMapActivity.java:76)
at com.example.webforest.quickaidlikeuber2nd.CustomerMapActivity.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)
请看它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
不在允许范围内。
看来你输入的纬度和经度顺序有误。
错误消息Not a valid geo location: -118.2541117, 33.985805
显示纬度后跟经度。 -118 度的纬度毫无意义。纬度值必须在 -90 到 +90 度范围内。
Please tell me how can solve this.
仔细检查你的代码,看看纬度和经度在哪里被调换了。
看起来可能在这里:
GeoQuery geoQuery = geoFire.queryAtLocation(
new GeoLocation(mLastLocation.getLongitude(),
mLastLocation.getLatitude()), 999999999);
您可以使用调试器进行验证。