android 开发使用最新百度地图如何画轨迹

 我来答
huanglenzhi
2015-02-01 · 知道合伙人数码行家
huanglenzhi
知道合伙人数码行家
采纳数:117538 获赞数:517192
长期从事计算机组装,维护,网络组建及管理。对计算机硬件、操作系统安装、典型网络设备具有详细认知。

向TA提问 私信TA
展开全部

android 使用百度地图画轨迹

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Path;
import android.graphics.Point;
import android.os.Bundle;
import com.baidu.mapapi.BMapManager;
import com.baidu.mapapi.GeoPoint;
import com.baidu.mapapi.MapActivity;
import com.baidu.mapapi.MapController;
import com.baidu.mapapi.MapView;
import com.baidu.mapapi.Overlay;
import com.baidu.mapapi.Projection;

public class BaiduMapActivity extends MapActivity {
        private Context mContext;
        private MapView mapView;
        @Override
        protected boolean isRouteDisplayed() {
                // TODO Auto-generated method stub
                return false;
        }
        private GeoPoint gpoint1, gpoint2, gpoint3;// 连线的点
        @Override
        protected void onCreate(Bundle arg0) {
                super.onCreate(arg0);
                setContentView(R.layout.baidumap_layout);

                BaseApplication baseApp = (BaseApplication) this.getApplication();
                if (baseApp.mBMapManage == null) {
                        baseApp.mBMapManage = new BMapManager(mContext);
                        baseApp.mBMapManage.init(baseApp.mStrKey,
                                        new BaseApplication.MyGeneralListener());
                }
                baseApp.mBMapManage.start();
                super.initMapActivity(baseApp.mBMapManage);// 初始化map sdk
                mapView = (MapView) findViewById(R.id.bmapView);
                mapView.setBuiltInZoomControls(true);
                // 设置在缩放动画过程中也显示overlay,默认为不绘制
                mapView.setDrawOverlayWhenZooming(true);

                // RouteLine routeLine =
                // (RouteLine)getIntent().getSerializableExtra("routeLine");

                //这里画点和连接线
                MyOverlay myOverlay = new MyOverlay();
                mapView.getOverlays().add(myOverlay);
                
                MapController mapController = mapView.getController();
                mapController.zoomIn();
                
                gpoint1 = new GeoPoint((int) (2259316 * 10),
                                (int) (11396279 * 10));
                gpoint2 = new GeoPoint((int) (2259245 * 10),
                                (int) (11396226 * 10));
                gpoint3 = new GeoPoint((int) (2259121 * 10),
                                (int) (11396066 * 10));                
                mapController.animateTo(gpoint1);//设置一个起点
        }

        class MyOverlay extends Overlay {

                @Override
                public void draw(Canvas canvas, MapView mapView, boolean shadow) {
                        super.draw(canvas, mapView, shadow);
                        
                        Projection projection = mapView.getProjection();
                        Point p1 = new Point();
                        Point p2 = new Point();
                        Point p3 = new Point();
                        // 经度转像素
                        projection.toPixels(gpoint1, p1);
                        projection.toPixels(gpoint2, p2);
                        projection.toPixels(gpoint3, p3);
                
                        //第一个画笔 画圆
                        Paint fillPaint = new Paint();
                        fillPaint.setColor(Color.BLUE);
                        fillPaint.setAntiAlias(true);
                        fillPaint.setStyle(Style.FILL);
                        
                        // 将图画到上层
                        canvas.drawCircle(p1.x, p1.y, 5.0f, fillPaint);
                        canvas.drawCircle(p2.x, p2.y, 5.0f, fillPaint);
                        canvas.drawCircle(p3.x, p3.y, 5.0f, fillPaint);

                        //第二个画笔 画线
                        Paint paint = new Paint();
                        paint.setColor(Color.BLUE);
                        paint.setDither(true);
                        paint.setStyle(Paint.Style.STROKE);
                        paint.setStrokeJoin(Paint.Join.ROUND);
                        paint.setStrokeCap(Paint.Cap.ROUND);
                        paint.setStrokeWidth(4);

                        //连接
                        Path path = new Path();
                        path.moveTo(p1.x, p1.y);
                        path.lineTo(p2.x, p2.y);
                        path.lineTo(p3.x, p3.y);
                        //画出路径
                        canvas.drawPath(path, paint);
                }
        }

}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
博思aippt
2024-07-20 广告
博思AIPPT是基于ai制作PPT的智能在线工具,它提供了4种AI制作PPT的方式,包括AI生成大纲、AI直接生成PPT、文本生成PPT、AI提炼文档生成PPT,一站式集成多种AI生成PPT的方式,可满足办公用户的不同需求和使用场景。ai生... 点击进入详情页
本回答由博思aippt提供
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式