2013-01-16 1 views
1

저는 이것을 반나절 동안 조사했는데 해결책을 찾지 못했습니다. 나에게 몇 가지 아이디어를 제안 해주세요.지도보기의 현재 위치에서 500 미터 지점에 원을 배치하십시오.

이 내가지도보기에 표시하는 방법입니다,

this is how i want to show in MapView

이 내가 얼마나되고,

this is how i get 그래서

, 그 원은 500m의 주위에 그려 질 것입니다 반경은 현재 위치를 중심으로합니다.

if(GPSTracker == true) 
{ 
    cl_drawable = getResources().getDrawable(R.drawable.blue); 
    cl_itemizedOverlay = new MyItemizedOverlay(cl_drawable, mapView, shadow); 
    mapView.getOverlays().clear(); 

    cur_loc = new GeoPoint((int)(latPt*1E6),(int)(lngPt*1E6)); 
    Log.e("Current place ", " is "+cur_loc); 
    cl_overlayItem = new OverlayItem(cur_loc, "current location", ""); 
    cl_itemizedOverlay.addOverlay(cl_overlayItem); 


    if(xxxx != 0) 
    { 
     drawable = getResources().getDrawable(R.drawable.yellow_pin); 
     itemizedOverlay = new MyItemizedOverlay(drawable, mapView, shadow); 

     for(int la=0;la<GoConstants.drink_venue_id.size();la++) 
     { 
      latpt = Double.valueOf(latd.get(la)); 
      lngpt = Double.valueOf(lond.get(la)); 

      p = new GeoPoint((int)(latpt*1E6),(int)(lngpt*1E6)); 
      overlayItem = new OverlayItem(p, GoConstants.xxxxx.get(la), ""); 
      itemizedOverlay.addOverlay(overlayItem); 
     } 

     mapOverlays.add(cl_itemizedOverlay); 
     mapOverlays.add(itemizedOverlay); 
     mapController = mapView.getController(); 
     mapController.animateTo(cur_loc); 
     mapController.setZoom(10); 
     mapView.getController().setCenter(cur_loc); 

이것은 내 코드의 일부입니다. 그리고 무엇을 어디에서 위에서 언급 한 mapView를 얻기 위해 코드를 배치해야합니까?

+2

당신이 http://stackoverflow.com/questions/5293709/draw-a-circle-on-android-mapview –

+0

을 확인 되세요 그것은 당신을 위해 OK인가? – breceivemail

+0

Thankyou @ GirishNair, 언급 된 링크로 해결되었습니다. – VIGNESH

답변

0

사용이 클래스 :

import java.util.ArrayList; 

import org.mabna.order.utils.Farsi; 

import android.app.AlertDialog; 
import android.content.Context; 
import android.graphics.Paint; 
import android.graphics.Point; 
import android.graphics.Rect; 
import android.graphics.RectF; 
import android.graphics.Typeface; 
import android.graphics.drawable.BitmapDrawable; 
import android.graphics.drawable.Drawable; 
import android.text.TextPaint; 

import com.google.android.maps.GeoPoint; 
import com.google.android.maps.ItemizedOverlay; 
import com.google.android.maps.MapView; 
import com.google.android.maps.OverlayItem; 

public class MapItemizedOverlay extends ItemizedOverlay<OverlayItem> { 
    // member variables 
    private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>(); 
    private Context mContext; 

    private int markerHeight; 
    private int mTextSize; 
    private int mTitleMargin; 

    private Typeface tf; 
    private boolean mDrawCircle; 
    private int mRadiusInMeter = 0; 

    public MapItemizedOverlay(Drawable defaultMarker, Context context, 
      int textSize, int titleMargin, boolean drawCircle) { 
     super(boundCenterBottom(defaultMarker)); 
     mContext = context; 
     mTextSize = textSize;   
     markerHeight = ((BitmapDrawable) defaultMarker).getBitmap().getHeight(); 
     mTitleMargin = titleMargin; 
     mDrawCircle = drawCircle; 
    } 

    // In order for the populate() method to read each OverlayItem, it will make 
    // a request to createItem(int) 
    // define this method to properly read from our ArrayList 
    @Override 
    protected OverlayItem createItem(int i) { 
     return mOverlays.get(i); 
    } 

    @Override 
    public int size() { 
     return mOverlays.size(); 
    } 

    @Override 
    protected boolean onTap(int index) { 
     OverlayItem item = mOverlays.get(index); 

     // Do stuff here when you tap, i.e. : 
     AlertDialog.Builder dialog = new AlertDialog.Builder(mContext); 
     dialog.setTitle(item.getTitle()); 
     dialog.setMessage(item.getSnippet()); 
     dialog.show(); 

     // return true to indicate we've taken care of it 
     return true; 
    } 



    @Override 
    public void draw(android.graphics.Canvas canvas, MapView mapView, 
      boolean shadow) { 
     super.draw(canvas, mapView, shadow); 

     // go through all OverlayItems and draw title for each of them 
     for (OverlayItem item : mOverlays) { 
      /* 
      * Converts latitude & longitude of this overlay item to coordinates 
      * on screen. As we have called boundCenterBottom() in constructor, 
      * so these coordinates will be of the bottom center position of the 
      * displayed marker. 
      */ 
      GeoPoint point = item.getPoint(); 
      Point markerBottomCenterCoords = new Point(); 
      mapView.getProjection().toPixels(point, markerBottomCenterCoords); 

      /* Find the width and height of the title */ 
      TextPaint paintText = new TextPaint(); 
      Paint paintRect = new Paint(); 

      Rect rectText = new Rect(); 
      paintText.setTextSize(mTextSize); 
      paintText.getTextBounds(item.getTitle(), 0, item.getTitle() 
        .length(), rectText); 

      rectText.inset(-mTitleMargin, -mTitleMargin); 
      rectText.offsetTo(
        markerBottomCenterCoords.x - rectText.width()/2, 
        markerBottomCenterCoords.y + 5); 

      paintText.setTextAlign(Paint.Align.CENTER); 
      paintText.setTextSize(mTextSize); 
      paintText.setARGB(255, 255, 255, 255); 
      // paintText.setFlags(Paint.FAKE_BOLD_TEXT_FLAG); 

      paintRect.setARGB(100, 0, 0, 0); 

      if (mDrawCircle && mapView != null) { 
       int radius = metersToRadius(mRadiusInMeter, mapView); 
       int arcWidth = (int) ((float) radius * 0.01); 
       arcWidth = arcWidth == 0 ? 1 : arcWidth; 

       Paint paintCircle = new Paint(); 
       paintCircle.setARGB(10, 0, 0, 255); 

       Paint paintArc = new Paint(); 
       // paintArc.setColor(Color.BLUE); 
       paintArc.setARGB(80, 0, 0, 255); 
       paintArc.setStrokeWidth(arcWidth); 
       paintArc.setAntiAlias(true); 
       paintArc.setStrokeCap(Paint.Cap.ROUND); 
       paintArc.setStyle(Paint.Style.STROKE); 

       RectF rectArc = new RectF(); 
       rectArc.set(markerBottomCenterCoords.x - radius, 
         markerBottomCenterCoords.y - radius, 
         markerBottomCenterCoords.x + radius, 
         markerBottomCenterCoords.y + radius); 

       canvas.drawCircle(markerBottomCenterCoords.x, 
         markerBottomCenterCoords.y, radius, paintCircle); 
       canvas.drawArc(rectArc, 0, 360, false, paintArc); 
      } 

      if (item.getTitle().length() > 0) { 
       canvas.drawRoundRect(new RectF(rectText), 2, 2, paintRect); 
       canvas.drawText(item.getTitle(), 
         rectText.left + rectText.width()/2, 
         rectText.bottom - mTitleMargin, paintText); 
      } 
     } 
    } 

    public void addOverlay(OverlayItem overlay) { 
     mOverlays.add(overlay); 
     populate(); 
    } 

    public void removeOverlay(OverlayItem overlay) { 
     mOverlays.remove(overlay); 
     populate(); 
    } 

    public void clear() { 
     mOverlays.clear(); 
     populate(); 
    } 

    public static int metersToRadius(float meters, MapView map) { 
     return (int) (map.getProjection().metersToEquatorPixels(meters)); 
    } 

    public void setRadius(int radiusInMeter) { 
     mRadiusInMeter = radiusInMeter; 
    } 
}