设为首页 加入收藏

TOP

Android教程:在百度地图上画出轨迹(二)
2014-11-24 07:40:22 来源: 作者: 【 】 浏览:7
Tags:Android 教程 百度 地图 轨迹
race.this.finish();
}
});
builder.create().show();
} else {
System.out.println("获得点后添加到图层");
// 添加ItemizedOverlay
Drawable marker = getResources().getDrawable(R.drawable.iconmarka); // 得到需要标在地图上的资源
marker.setBounds(0, 0, marker.getIntrinsicWidth(),
marker.getIntrinsicHeight()); // 为maker定义位置和边界


mMapView.getOverlays().add(new OverItemT(marker, this, myTraces)); // 添加ItemizedOverlay实例到mMapView


// 创建点击mark时的弹出泡泡
mPopView = super.getLayoutInflater()
.inflate(R.layout.popview, null);
mMapView.addView(mPopView, new MapView.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, null,
MapView.LayoutParams.TOP_LEFT));
mPopView.setVisibility(View.GONE);
}


}


@Override
protected void onPause() {
BMapApp app = (BMapApp) this.getApplication();
app.mBMapMan.getLocationManager().removeUpdates(mLocationListener);
mLocationOverlay.disableMyLocation();
mLocationOverlay.disableCompass(); // 关闭指南针
app.mBMapMan.stop();
super.onPause();
}


@Override
protected void onResume() {
BMapApp app = (BMapApp) this.getApplication();
// 注册定位事件,定位后将地图移动到定位点
app.mBMapMan.getLocationManager().requestLocationUpdates(
mLocationListener);
mLocationOverlay.enableMyLocation();
mLocationOverlay.enableCompass(); // 打开指南针
app.mBMapMan.start();
super.onResume();
}


@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}


}


class OverItemT extends ItemizedOverlay {


private List mGeoList = new ArrayList();
private Drawable marker;
private Context mContext;
private ArrayList traces = new ArrayList();


public OverItemT(Drawable marker, Context context, ArrayList traces) {
super(boundCenterBottom(marker));


this.marker = marker;
this.mContext = context;
this.traces = traces;
// 用给定的经纬度构造GeoPoint,单位是微度 (度 * 1E6)
// 构造OverlayItem的三个参数依次为:item的位置,标题文本,文字片段
for (int i = 0; i < traces.size(); i++) {
int lat = new Integer(traces.get(i).getLatitude());
int lon = new Integer(traces.get(i).getLongitude());
String resName = traces.get(i).getResname();
GeoPoint p = new GeoPoint(lat, lon);
mGeoList.add(new OverlayItem(p, resName, i + resName));
populate(); // createItem(int)方法构造item。一旦有了数据,在调用其它方法前,首先调用这个方法
}


}


@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {


// Projection接口用于屏幕像素坐标和经纬度坐标之间的变换
Projection projection = mapView.getProjection();
for (int index = size() - 1; index >= 0; index--) { // 遍历mGeoList
OverlayItem overLayItem = getItem(index); // 得到给定索引的item


String title = overLayItem.getTitle();
// 把经纬度变换到相对于MapView左上角的屏幕像素坐标
Point point = projection.toPixels(overLayItem.getPoint(), null);


// 可在此处添加您的绘制代码
Paint paintText = new Paint();
paintText.setColor(Color.BLUE);
paintText.setTextSize(15);
canvas.drawText(title, point.x - 30, point.y, paintText); // 绘制文本
}


super.draw(canvas, mapView, shadow);
// 调整一个drawable边界,使得(0,0)是这个drawable底部最后一行中心的一个像素
// 先所有点的经度转像素
ArrayList points = new ArrayList();
for (int i = 0; i < this.size(); i++) {
Point p = new Point();
OverlayItem overLayItem = getItem(i);
projection.toPixels(overLayItem.getPoint(), p);
points.add(p);
}
// 第二个画笔 画线
Paint paint = new Paint();
paint.setColor(Color.BLUE);
paint.setDither(true);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeJoin(Paint.Join.ROUND);

首页 上一页 1 2 3 下一页 尾页 2/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Android4.0 输出分辨率改为1280*7.. 下一篇Linux设备驱动的Hello World—LED..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Asus Armoury Crate (2025-12-26 02:52:33)
·WindowsFX (LinuxFX) (2025-12-26 02:52:30)
·[ Linux运维学习 ] (2025-12-26 02:52:27)
·HTTPS 详解一:附带 (2025-12-26 02:20:37)
·TCP/IP协议到底在讲 (2025-12-26 02:20:34)