java.lang.IllegalStateException:android中的片段中没有包含点
在我的片段中,我得到错误java.lang.IllegalStateException:无包含点== 我尝试了很多解决方案,但都不奏效 这是我的密码:java.lang.IllegalStateException:android中的片段中没有包含点,android,google-maps,Android,Google Maps,在我的片段中,我得到错误java.lang.IllegalStateException:无包含点== 我尝试了很多解决方案,但都不奏效 这是我的密码: public void mSetUpMap() { /**clear the map before redraw to them*/ googleMap.clear(); /**Create dummy Markers List*/ if (AppUtil.itinerary != null)
public void mSetUpMap() {
/**clear the map before redraw to them*/
googleMap.clear();
/**Create dummy Markers List*/
if (AppUtil.itinerary != null)
str = AppUtil.itinerary.getItinerary();
if (AppUtil.itinerary != null)
shareUrl = AppUtil.itinerary.getShareUrl();
Log.e("Ittt", "" + AppUtil.itinerary.getItinerary());
((HomeActivity) getActivity()).setTexrViewText(str);
poiList.clear();
poiList = AppUtil.itinerary.getPoiList();
final List<Marker> markersList = new ArrayList<>();
for (POI item : poiList) {
Marker m1 = googleMap.addMarker(new MarkerOptions().position(new
LatLng(item.getLatitude(),
item.getLongitude()))
.title(item.getName()).anchor(0.7f, 0.6f)
.icon(BitmapDescriptorFactory.fromBitmap(getCustomMarker
((R.drawable.m2red),
item.getName()))));
markersList.add(m1);
}
builder = new LatLngBounds.Builder();
for (Marker m : markersList) {
builder.include(m.getPosition());
}
/**initialize the padding for map boundary*/
int padding = 200;
/**create the bounds from latlngBuilder to set into map camera*/
LatLngBounds bounds = builder.build();
/**create the camera with bounds and padding to set into map*/
cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);
/**call the map call back to know map is loaded or not*/
googleMap.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() {
@Override
public void onMapLoaded() {
/**set animated zoom camera into map*/
googleMap.animateCamera(cu);
PolylineOptions polylineOptions = new PolylineOptions();
for (POI item : poiList) {
polylineOptions.add(new LatLng(item.getLatitude(),
item.getLongitude()));
}
polylineOptions.width(5);
polylineOptions.getPoints();
polylineOptions.color(getResources().getColor(R.color.red));
googleMap.addPolyline(polylineOptions);
polylineOptions.geodesic(true);
if (!poiList.isEmpty()) {
// Adjusting Bounds
LatLngBounds.Builder builder = new LatLngBounds.Builder();
for (Marker m : markersList) {
builder.include(m.getPosition());
}
LatLngBounds bounds = builder.build();
CameraUpdate mCameraUpdate =
CameraUpdateFactory.newLatLngBounds(bounds, 2);
googleMap.animateCamera(mCameraUpdate);
}
}
});
googleMap.setOnMarkerClickListener(new
GoogleMap.OnMarkerClickListener()
{
@Override
public boolean onMarkerClick(final Marker marker) {
ValueAnimator ani = ValueAnimator.ofFloat(0, 1); //change for
(0,1) if you want a fade in
ani.setDuration(2000);
ani.addUpdateListener(new ValueAnimator.AnimatorUpdateListener()
{
@Override
public void onAnimationUpdate(ValueAnimator animation) {
marker.setAlpha((float) animation.getAnimatedValue());
}
});
ani.start();
if (marker.getTitle().equals(poiList.get(0).getName())) {
AppUtil.poi = poiList.get(0);
name = poiList.get(0).getName();
img = poiList.get(0).getImage();
lat = poiList.get(0).getLatitude();
lon = poiList.get(0).getLongitude();
showPoi(name, img, lat, lon);
} else if (marker.getTitle().equals(poiList.get(1).getName())) {
AppUtil.poi = poiList.get(1);
name = poiList.get(1).getName();
img = poiList.get(1).getImage();
lat = poiList.get(1).getLatitude();
lon = poiList.get(1).getLongitude();
showPoi(name, img, lat, lon);
} else if (marker.getTitle().equals(poiList.get(2).getName())) {
AppUtil.poi = poiList.get(2);
name = poiList.get(2).getName();
img = poiList.get(2).getImage();
lat = poiList.get(2).getLatitude();
lon = poiList.get(2).getLongitude();
showPoi(name, img, lat, lon);
}
return true;
}
});
}
您不需要检查poiList是否为空,而是需要检查
setOnMapLoadedCallback
方法中的markersList是否为空
if (!markersList.isEmpty()) {
// Adjusting Bounds
LatLngBounds.Builder builder = new LatLngBounds.Builder();
for (Marker m : markersList) {
builder.include(m.getPosition());
}
LatLngBounds bounds = builder.build();
CameraUpdate mCameraUpdate =
CameraUpdateFactory.newLatLngBounds(bounds, 2);
googleMap.animateCamera(mCameraUpdate);
}
从错误中看,您的
标记列表
似乎为空。它需要至少包含一个点,才能使LatLngBounds.Builder
正常工作。发布完整的例外情况请参见编辑的问题@Redman
if (!markersList.isEmpty()) {
// Adjusting Bounds
LatLngBounds.Builder builder = new LatLngBounds.Builder();
for (Marker m : markersList) {
builder.include(m.getPosition());
}
LatLngBounds bounds = builder.build();
CameraUpdate mCameraUpdate =
CameraUpdateFactory.newLatLngBounds(bounds, 2);
googleMap.animateCamera(mCameraUpdate);
}