首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 开源软件 >

在Google舆图上绘制直线

2012-07-02 
在Google地图上绘制直线?mars chen 老师第三季视频 08集绘制路线的步骤? 1.确定路线的起始和终止的经纬度

在Google地图上绘制直线


?mars chen 老师第三季视频 08集

绘制路线的步骤

? 1.确定路线的起始和终止的经纬度坐标

??2在起点和终点上绘制图标

? 3将经纬度坐标换算成屏幕上x轴/y轴坐标

? 4在起点和终点绘制直线

代码如下:

public class MainActivity extends MapActivity {private GeoPoint beginGeoPoint;private GeoPoint endGeoPoint;private MapController mapController;private List<Overlay> overlays;private Projection projection;@Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);                //指定起始和终止位置经纬度        beginGeoPoint=new GeoPoint(19240000,-99120000);        endGeoPoint=new GeoPoint(19340000,-99220000);                MapView mapView=(MapView)findViewById(R.id.mapview);        mapView.setBuiltInZoomControls(true);                //对地图进行控制        mapController=mapView.getController();        overlays=mapView.getOverlays();        projection=mapView.getProjection();                overlays.add(new PointOverlay(beginGeoPoint));        overlays.add(new PointOverlay(endGeoPoint));        overlays.add(new LineOverlay(beginGeoPoint,endGeoPoint));                //        mapController.animateTo(beginGeoPoint);        mapController.setZoom(12);            }@Overrideprotected boolean isRouteDisplayed() {return false;}//该类对象用于在地图上绘制线条 class LineOverlay extends Overlay{private GeoPoint begin;private GeoPoint end;public LineOverlay() {}public LineOverlay(GeoPoint begin, GeoPoint end) {this.begin = begin;this.end = end;}//canvas画布 paint画笔@Overridepublic void draw(Canvas canvas, MapView mapView, boolean shadow) {super.draw(canvas, mapView, shadow);Paint paint=new Paint();paint.setColor(Color.BLUE);paint.setStyle(Paint.Style.FILL_AND_STROKE);paint.setStrokeWidth(2);Point beginPoint=new Point();Point endPoint=new Point();Path path=new Path();projection.toPixels(beginGeoPoint,beginPoint);projection.toPixels(endGeoPoint, endPoint);path.moveTo(endPoint.x, endPoint.y);path.lineTo(beginPoint.x, beginPoint.y);canvas.drawPath(path, paint);}}//绘制图标class PointOverlay extends Overlay{private GeoPoint geoPoint;public PointOverlay() {}public PointOverlay(GeoPoint geoPoint) {super();this.geoPoint = geoPoint;}@Overridepublic void draw(Canvas canvas, MapView mapView, boolean shadow) {super.draw(canvas, mapView, shadow);Point point=new Point();projection.toPixels(geoPoint,point);Bitmap bmp=BitmapFactory.decodeResource(getResources(), R.drawable.tool);Paint paint=new Paint();canvas.drawBitmap(bmp, point.x, point.y-10,paint);}}}

?

效果图:

?
在Google舆图上绘制直线
?最近有点忙,等有时间了。一定好好琢磨琢磨,写个漂亮实用的地图出来。先记录下来,备忘。

?

热点排行