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() {
-
- 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);
- mapView = (MapView) findViewById(R.id.bmapView);
- mapView.setBuiltInZoomControls(true);
-
- mapView.setDrawOverlayWhenZooming(true);
-
-
-
-
-
- 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);
- }
- }
-
- }
原文地址:https://www.cnblogs.com/rollrock/p/2622819.html