Android在转盘幻灯片上更改标记图标

时间:2017-05-17 04:03:15

标签: java android google-maps maps

我想请求您的帮助,或者您是否已经实施了我的项目的其中一项要求。我有一个mapfragment,它有一个记录的旋转木马,在地图上也有各自的标记。

这是我目前的代码:

for (int counter = 0; counter < foodList.size(); counter++) {
        if (counter == midValue) {

            LatLng foodLocation = new LatLng(foodList.get(counter).Lat, foodList.get(counter).Long);

            MarkerOptions mo = new MarkerOptions()
                    .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ORANGE))
                    .position(foodLocation)
                    .rotation(0)
                    .title(counter + 1 + ") " + foodList.get(counter).List_Name);

            Marker mkr = mMap.addMarker(mo);
            mMarkers.put(mkr.getId(), counter);

            previousMarker = mMap.addMarker(
                    new MarkerOptions().position(foodLocation)
                            .title(counter + 1 + ") " + foodList.get(counter).List_Name)
                            .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ORANGE))
                            .snippet(foodList.get(counter).List_ID)
                            );

            CameraUpdate center = CameraUpdateFactory.newLatLng(foodLocation);
            CameraUpdate zoom = null;

            if (foodList.size() <= 5) {
                zoom = CameraUpdateFactory.zoomTo(cameraLevel);
            } else {
                zoom = CameraUpdateFactory.zoomTo(cameraLevelMany);
            }

            mMap.moveCamera(center);
            mMap.animateCamera(zoom);

        } else {
            LatLng foodLocation = new LatLng(foodList.get(counter).Lat, foodList.get(counter).Long);

            MarkerOptions mo = new MarkerOptions()
                    .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ORANGE))
                    .position(foodLocation)
                    .rotation(0)
                    .title(counter + 1 + ") " + foodList.get(counter).List_Name);

            Marker mkr = mMap.addMarker(mo);
            mMarkers.put(mkr.getId(), counter);
        }

        mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
            @Override
            public boolean onMarkerClick(Marker clickedMarker) {
                String title = clickedMarker.getTitle();

                int id = mMarkers.get(clickedMarker.getId());
                clickedMarker.showInfoWindow();

                try {
                    String num = title.substring(0, title.indexOf(")"));
                    midValue = Integer.parseInt(num) - 1;

                    if (previousMarker != null) {previousMarker.setIcon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED));
                    }
                    clickedMarker.setIcon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ORANGE));
                    previousMarker = clickedMarker;
                    // end

                    mViewPager.setCurrentItem(midValue, false);
                    midValue = mViewPager.getCurrentItem();
                    isMarkerClicked = true;

                    new Handler().postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            mViewPager.beginFakeDrag();
                            mViewPager.fakeDragBy(0.1f);
                            mViewPager.endFakeDrag();
                            isMarkerClicked = false;
                        }
                    }, 100);

                    Food food = foodList.get(id);

                    Intent intent = new Intent(ProductMapsActivity.this, ProductDetailActivity.class);
                    intent.putExtra("ownLat", ownLat);
                    intent.putExtra("ownLong", ownLong);
                    startActivity(intent);

                } catch (Exception ex) {
                    clickedMarker.showInfoWindow();
                }
                return true;
            }
        });
    }

    View zoomControls = mapFragment.getView().findViewById(0x1);

    if (zoomControls != null && zoomControls.getLayoutParams() instanceof RelativeLayout.LayoutParams) {
        // ZoomControl is inside of RelativeLayout
        RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) zoomControls.getLayoutParams();

        // Align it to - parent top|left
        params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
        params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);

        // Update margins, set to 10dp
        final int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10,
                getResources().getDisplayMetrics());
        params.setMargins(margin, margin, margin, margin);
    }

现在这仅在您单击标记时有效。这没关系,但不是我需要的。你有任何想法如何实现这一目标?我非常感谢任何帮助。谢谢。

0 个答案:

没有答案