android - 如何修复“java.lang.IllegalArgumentException:不是有效的地理位置:-118.2541117, 33.985805”
问题描述
我正在我的应用程序中设置当前位置。但它崩溃了
在 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)
解决方案
看起来您的纬度和经度顺序错误。
错误消息Not a valid geo location: -118.2541117, 33.985805
显示纬度后跟经度。-118 度的纬度毫无意义。纬度值必须在 -90 到 +90 度的范围内。
请告诉我如何解决这个问题。
仔细检查您的代码以查看在哪里切换了纬度和经度。
看起来它可能在这里:
GeoQuery geoQuery = geoFire.queryAtLocation(
new GeoLocation(mLastLocation.getLongitude(),
mLastLocation.getLatitude()), 999999999);
您可以使用调试器进行验证。
推荐阅读
- javascript - 查找所有标签并用它们的 src (NODEJS) 替换它们
- python - 插入列但合并单元格有问题
- javascript - 未捕获的 ReferenceError:在初始化之前无法访问“jobTreeReducers”
- python - 同一CNN上的不同精度
- angular - 条件RouterLinkActive
- jenkins - Git使用用户名和密码在jenkins管道中签出外部项目
- hibernate - JPA与关系模型中双向关系的概念
- typescript - 删除一条与nest js有多对多关系的记录,输入ORM
- javascript - 如何检测浏览器环境并导出模块?
- android - 为什么在片段 Kotlin 上使用“this”时会出现类型不匹配