我尝试如图所示在android的google地图上的两个位置之间绘制折线,如图所示我尝试如图所示在android的google map上的两个位置之间绘制折线,如何绘制?
我尝试下面的代码,但是它不起作用
这是我的代码:
public void mSetUpMap() {
googleMap.clear();
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();
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.39f, 0.39f)
.icon(BitmapDescriptorFactory.fromBitmap(getCustomMarker
((R.drawable.m2red), item.getName()))));
}
googleMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener()
{
@Override
public boolean onMarkerClick(final Marker marker) {
ValueAnimator ani = ValueAnimator.ofFloat(0, 1);
ani.setDuration(2000);
ani.addUpdateListener(new ValueAnimator.AnimatorUpdateListener()
{
@Override
public void onAnimationUpdate(ValueAnimator animation) {
marker.setAlpha((float) animation.getAnimatedValue());
}
});
ani.start();
return true;
}
});
/**create for loop for get the latLngbuilder from the marker list*/
builder = new LatLngBounds.Builder();
for (Marker m : markersList) {
builder.include(m.getPosition());
}
int padding = 200;
LatLngBounds bounds = builder.build();
cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);
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(3);
polylineOptions.getPoints();
polylineOptions.getPoints();
polylineOptions.color(getResources().getColor(R.color.red));
Polyline line = googleMap.addPolyline(polylineOptions);
}
});
}
答案 0 :(得分:3)
只需更改此代码:
Marker m1 = googleMap.addMarker(new MarkerOptions().position(new
LatLng(item.getLatitude(), item.getLongitude()))
.title(item.getName()).anchor(0.6f, 0.7f)
.anchor()方法有效