如何在Android中的谷歌地图中设置折线填充

时间:2018-08-29 05:21:06

标签: android google-maps google-polyline

我尝试在两者之间画一条折线 Google地图上的两个或多个位置 但是我

需要如图所示的多段线

正确,但可以显示错误的地图 第一张图片有误

第二张图片正确 如何设置像正确图像一样的折线

我如何在谷歌地图上的经纬度和折线之间设置边距或填充

wrong image correct image

我的代码是:

    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 个答案:

没有答案