Android 在地图视图中,在距离当前位置约500米处放置一个圆圈

Android 在地图视图中,在距离当前位置约500米处放置一个圆圈,android,map,android-mapview,Android,Map,Android Mapview,我找了半天,找不到解决办法。请给我一些建议 这就是我想在MapView中显示的方式 我就是这样得到的 所以,这个圆的半径是500米,以当前位置为中心 if(GPSTracker == true) { cl_drawable = getResources().getDrawable(R.drawable.blue); cl_itemizedOverlay = new MyItemizedOverlay(cl_drawable, mapView, shadow); map

我找了半天,找不到解决办法。请给我一些建议

这就是我想在MapView中显示的方式

我就是这样得到的

所以,这个圆的半径是500米,以当前位置为中心

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);
if(GPSTracker==true)
{
cl_drawable=getResources().getDrawable(R.drawable.blue);
cl_itemizedOverlay=新的MyItemizedOverlay(cl_可绘制、地图视图、阴影);
mapView.getOverlays().clear();
cur_loc=新的地质点((int)(latPt*1E6),(int)(lngPt*1E6));
日志e(“当前位置”、“is”+当前位置);
cl_overlayItem=新的overlayItem(当前位置,“当前位置”);
cl_itemizedOverlay.addOverlay(cl_overlayItem);
如果(xxxx!=0)
{
drawable=getResources().getDrawable(R.drawable.yellow_-pin);
itemizedOverlay=新的MyItemizedOverlay(可绘制、地图视图、阴影);
对于(int la=0;la使用该类:

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;
    }
}
import java.util.ArrayList;
导入org.mabna.order.utils.Farsi;
导入android.app.AlertDialog;
导入android.content.Context;
导入android.graphics.Paint;
导入android.graphics.Point;
导入android.graphics.Rect;
导入android.graphics.RectF;
导入android.graphics.Typeface;
导入android.graphics.drawable.BitmapDrawable;
导入android.graphics.drawable.drawable;
导入android.text.TextPaint;
导入com.google.android.maps.GeoPoint;
导入com.google.android.maps.ItemizedOverlay;
导入com.google.android.maps.MapView;
导入com.google.android.maps.OverlayItem;
公共类MapItemizeOverlay扩展了ItemizeOverlay{
//成员变量
private ArrayList mOverlays=new ArrayList();
私有上下文;
私人国际马克黑度;
私有int-mTextSize;
私人内特梅特梅金;
专用字体tf;
私有布尔圆;
专用int mRadiusInMeter=0;
公共MapItemizeOverlay(可绘制的默认标记、上下文、,
int textSize、int titleMargin、布尔绘图圈){
super(boundCenterBottom(defaultMarker));
mContext=上下文;
mTextSize=textSize;
markerHeight=((BitmapDrawable)defaultMarker.getBitmap().getHeight();
mTitleMargin=titleMargin;
mDrawCircle=drawCircle;
}
//为了让populate()方法读取每个OverlayItem,它将
//对createItem(int)的请求
//定义此方法以正确读取ArrayList
@凌驾
受保护的OverlayItem createItem(int i){
返回mOverlays.get(i);
}
@凌驾
公共整数大小(){
返回mOverlays.size();
}
@凌驾
受保护的布尔onTap(整数索引){
OverlayItem item=mOverlays.get(索引);
//轻触时在此处执行操作,即:
AlertDialog.Builder dialog=新建AlertDialog.Builder(mContext);
setTitle(item.getTitle());
setMessage(item.getSnippet());
dialog.show();
//返回true表示我们已处理它
返回true;
}
@凌驾
public void draw(android.graphics.Canvas画布、MapView MapView、,
布尔阴影){
super.draw(画布、地图视图、阴影);
//检查所有覆盖项目,并为每个项目绘制标题
对于(覆盖项项目:mOverlays){
/*
*将此覆盖项的纬度和经度转换为坐标
*正如我们在构造函数中调用boundCenterBottom()一样,
*所以这些坐标将是物体的底部中心位置
*显示的标记。
*/
地理点=item.getPoint();
点标记BottomCenterCoords=新点();
mapView.getProjection().toPixels(点、markerBottomCenterCoords);
/*查找标题的宽度和高度*/
TextPaint paintText=新建TextPaint();
Paint paintRect=新油漆();
Rect rectText=new Rect();
paintText.setTextSize(mTextSize);
paintText.getTextBounds(item.getTitle(),0,item.getTitle())
.length(),文本);
插入(-mTitleMargin,-mTitleMargin);
rectText.offsetTo(
markerBottomCenterCoords.x-rectText.width()/2,
markerBottomCenterCoords.y+5);
paintText.setTextAlign(Paint.Align.CENTER);
paintText.setTextSize(mTextSize);
setARGB(255、255、255、255);
//paintText.setFlags(Paint.false\u BOLD\u TEXT\u FLAG);
paintRect.setARGB(100,0,0,0);
if(mdrawcirle&&mapView!=null){
int radius=米半径(mRadiusInMeter,mapView);
int弧宽=(int)((浮动)半径*0.01);
弧宽=弧宽==0?1:弧宽;
绘制画圈=新绘制();
paintCircle.setARGB(10,0,0255);
油漆弧=新油漆();
//paintArc.setColor(Color.BLUE);
paintArc.setARGB(80,0,0255);
油漆弧设置行程宽度(弧宽);
paintArc.setAntiAlias(真);
油漆弧固定行程盖(油漆盖圆形);
paintArc.setStyle(Paint.Style.STROKE);
RectF rectArc=新的RectF();
矩形弧.set(markerBottomCenterCoords.x-半径,
markerBottomCenterCoords.y-半径,
markerBottomCenterCoords.x+半径,
markerBottomCenterCoords.y+半径);
canvas.drawCircle(markerBottomCenterCoords.x,
MarkerBottom中心坐标y、半径、画圈);
画布.drawArc(矩形、0、360、假、彩弧);
}
if(item.getTitle().len)