0

I am using google Api version-2 for google maps ,I want to refresh my google map ,is it possible to refresh using api-version-2 ? can we use VisualRefresh option in api-v2?

my code is as below-

public class ClustringActivity extends Activity{
    View view;  
    MapView mapView;
    GoogleMap map;
    List<PointOfInterest> pointsOfInterest;
    Clusterer<PointOfInterest> clusterer;
    HashMap<Marker, PointOfInterest> markers = new HashMap<Marker, PointOfInterest>();
    HashMap<Marker, Cluster> clusters = new HashMap<Marker, Cluster>();

    @Override 
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();



    }

    private void createDummyLocations() {
        pointsOfInterest = new ArrayList<PointOfInterest>();
        pointsOfInterest.add(new PointOfInterest(new LatLng(12.9065534, 77.57748019999997), "Perry's house", "Very beautiful"));

        pointsOfInterest.add(new PointOfInterest(new LatLng(12.9169534, 77.67748019999997), "Cottolengo",
                "Greatest munye-munye I've ever tasted"));
        pointsOfInterest.add(new PointOfInterest(new LatLng(12.915295, 77.573647), "Banashankari",
                " Metro Station"));
        pointsOfInterest.add(new PointOfInterest(new LatLng(12.905974, 77.580664), "17th Cross Road",
                "Bus Station"));
        pointsOfInterest.add(new PointOfInterest(new LatLng(12.91091, 77.581694), "Mirambika School for New Age",
                "Sri Aurobindo Marg, 1st phase, Phase I, Bangalore, KA, India"));
        pointsOfInterest.add(new PointOfInterest(new LatLng(12.904426, 77.573755), "Pizza HUt",
                "BKN Plaza, Opposite Family Mart, 363/70, Kanakapura Road, Jarganahalli, JP Nagar VI Phase, Bangalore, Karnataka, India"));
    }

    private void initMap() {
        if (mapView==null) return;
        CameraPosition cameraPosition = new CameraPosition.Builder().target(new LatLng(12.910491, 77.580117)).zoom(15).build();

        map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
        map.setOnMarkerClickListener(new OnMarkerClickListener() {

            @Override
            public boolean onMarkerClick(Marker marker) {
                if (markers.containsKey(marker)) {
                    Toast.makeText(ClustringActivity.this, "Poi clicked!", Toast.LENGTH_LONG).show();
                } else if (clusters.containsKey(marker)){
                    Toast.makeText(ClustringActivity.this, "Cluster clicked!", Toast.LENGTH_LONG).show();
                }
                return false;
            }
        });
    }

    private void initClusterer() {
        clusterer = new Clusterer<PointOfInterest>(this, map);
        clusterer.addAll(pointsOfInterest);
          Toast.makeText(getApplicationContext(), "refresh....", Toast.LENGTH_SHORT).show();    
        clusterer.setOnPaintingMarkerListener(new OnPaintingMarkerListener<PointOfInterest>() {

            @Override
            public void onMarkerCreated(Marker marker, PointOfInterest clusterable) {
                markers.put(marker, clusterable);
            }

            @Override
            public MarkerOptions onCreateMarkerOptions(PointOfInterest clusterable) {
                PointOfInterest poi = (PointOfInterest) clusterable;
                return new MarkerOptions().position(clusterable.getPosition()).title(poi.getName()).snippet(poi.getDescription());
            }
        });

        clusterer.setOnPaintingClusterListener(new OnPaintingClusterListener() {

            @Override
            public void onMarkerCreated(Marker marker, Cluster cluster) {
                clusters.put(marker, cluster);
            }

            @Override
            public MarkerOptions onCreateClusterMarkerOptions(Cluster cluster) {

                /*View marker = ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.custom_marker_layout, null);
                TextView numTxt = (TextView) marker.findViewById(R.id.num_txt);
                numTxt.setText(cluster.getWeight());*/

                return new MarkerOptions()
                        .title("Clustering " + cluster.getWeight() + " items")
                        .position(cluster.getCenter())
                        .icon(BitmapDescriptorFactory.fromBitmap(getClusteredLabel(Integer.valueOf(cluster.getWeight()).toString(),
                                ClustringActivity.this)));
                        /*.icon(BitmapDescriptorFactory.fromBitmap(createDrawableFromView(ClustringActivity.this, marker)));*/
            }
        });

    }

    private Bitmap getClusteredLabel(String cnt, Context ctx) {
        Resources r = ctx.getResources();
        Bitmap res = BitmapFactory.decodeResource(r, R.drawable.custom_marker);
        res = res.copy(Bitmap.Config.ARGB_8888, true);
        Canvas c = new Canvas(res);

        Paint textPaint = new Paint();
        textPaint.setAntiAlias(true);
        textPaint.setTextAlign(Paint.Align.CENTER);      
        textPaint.setTypeface(Typeface.DEFAULT_BOLD);
        textPaint.setColor(Color.BLUE);
        textPaint.setTextSize(40);


        c.drawText(cnt, res.getWidth() / 3 +textPaint.getTextSize() / 4, res.getHeight()/2 , textPaint);

        return res;    
    }

I tried using invalidate() but it will apply on View only please suggest some idea using java code or if possible javaScript?

4

1 回答 1

0

看起来你正在使用这个库。通过查看代码,它看起来像是强制更新,您需要调用:

clusterer.forceUpdate()

这应该重新聚集所有视图。

于 2013-08-14T09:33:21.980 回答