0

マップを使用してアプリを作成しています。アイテム化されたオーバーレイを使用して特定のポイントに円を描いていますが、かなりうまく機能します。しかし、その円の半径をシークバーの進行状況の値で変更したいと考えています。誰でも私をこれに導くことができますか 事前に感謝します。

4

2 に答える 2

2

マップ上で円を描くにはitemoziedOverlayを使用する必要がありますが、Progress of Seek Barで変更するには、Seek Barで機能する次のことを行う必要があります。また、SeekBarを使用してズームレベルを設定する場合もあります。次のコードで処理されますSnippet

注:最小値が0、最大値が9のシークバーを使用しました

   public void seekBarProgressEvent()
    {
        seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                // TODO Auto-generated method stub


            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onProgressChanged(SeekBar seekBar, int progress,
                    boolean fromUser) {
                // TODO Auto-generated method stub
                mapView.getOverlays().clear();

                if(progress==0)
                {
                    zoomLevel=17f;



                }
                else if(progress==1)
                {
                    zoomLevel=16f;



                }
                else if(progress==2)
                {
                    zoomLevel=15f;



                }
                else if(progress==3)
                {
                    zoomLevel=14f;



                }
                else if(progress==4)
                {
                    zoomLevel=14f;



                }
                else if(progress==5)
                {
                    zoomLevel=13.50f;



                }
                else if(progress==6)
                {
                    zoomLevel=13.10f;


                }
                else if(progress==7)
                {
                    zoomLevel=12.85f;


                }
                else if(progress==8)
                {
                    zoomLevel=12.10f;


                }
                else if(progress==9)
                {
                    zoomLevel=11.85f;

                }
                //intent.putExtra("radius", radius);
                //zoomLevel-=seekBar.getProgress();
                Log.i("ZoomLevel", ""+zoomLevel);
                mapView.getController().setZoom((int)zoomLevel);
                Drawable drawable = getApplicationContext().getResources().getDrawable(R.drawable.mapmarker);
// in Itemized overlay i m drawing circle of  Defined Radius like 100m 200m 300m etc
                itemizedoverlay = new FolloowMapOverlay(drawable, getApplicationContext(),(radius));
                MapPoint = new GeoPoint((int)(mylat*1E6), (int)(mylon*1E6));
                OverlayItem overlayitem = new OverlayItem(MapPoint, "Current Location", "");
                currentLocationOverlay = new CurrentLocationOverlay(drawable, getApplicationContext());
                currentLocationOverlay.addOverlay(overlayitem);        
                mapView.getOverlays().add(itemizedoverlay);  
                mapView.getOverlays().add(currentLocationOverlay);  
                mapView.invalidate();
                mapController.setCenter(MapPoint);
                mapController.animateTo(MapPoint);
            }
        });

    }

以下は、アイテム化されたオーバーレイクラスのDrawCircleメソッドです。

 private void drawCircleAtPoint(GeoPoint point, Canvas canvas, MapView mapView) {

        Projection projection = mapView.getProjection();        
        Point pt2 = new Point();
        projection.toPixels(point, pt2);
// method that is used to conver the radius to pixel that takes input the radius and draw it on the coresponding pixels 
        float circleRadius = projection.metersToEquatorPixels(radius) * (1/ FloatMath.cos((float) Math.toRadians(MapController.mylat)));
        Paint circlePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        Paint rectangle=new Paint(Paint.ANTI_ALIAS_FLAG);
        Log.d("Circular Radius", ""+circleRadius+"             "+radius);

        circlePaint.setColor(0x99000000);
        circlePaint.setStyle(Style.STROKE);
        canvas.drawCircle((float)pt2.x, (float)pt2.y, circleRadius, circlePaint);




    }
于 2013-01-11T07:16:45.723 に答える
1

Androidの公式ガイドであるGoogleから提供された優れたサンプルとチュートリアルを紹介します。

まず、GoogleDevガイドでこのサイトにアクセスします。

次に、上記のガイドを参照しているサンプルコードをGoogleDevガイドのこちらから入手してください。

3番目に、上記のサンプルコードのsrc/ディレクトリで「PolylineDemoActivity.java」を見つけます。それがあなたが知りたいことだと思います。

シークバーの進行値を使用して円の半径を変更できます〜!

円の半径を変更できます

詳細については、私に連絡してください。

于 2013-01-17T13:32:58.720 に答える