【发布时间】:2010-10-31 22:48:23
【问题描述】:
我正在使用下面的代码在我的 MapView 上放置一个叠加层。出于某种原因,在遍历位置数据后,它会在同一个地方绘制点。
从位置到地理点到投影的转换似乎正在发生:
Location (lat : lon) 51.2651789188385 : -0.5398589372634888
Projection (x : y) 239 : 361
Location (lat : lon) 51.26375198364258 : -0.5417096614837646
Projection (x : y) 239 : 361
地点是双打的 地理点是整数 投影是屏幕坐标。
有人可以看看下面的代码,看看我做错了什么吗?
谢谢
导入 java.util.ArrayList;
导入 java.util.HashMap;
导入 java.util.Iterator;
导入android.content.Context;
导入android.graphics.Canvas;
导入android.graphics.Color;
导入android.graphics.Paint;
导入android.graphics.Point;
导入android.graphics.RectF;
导入android.location.Location;
导入android.util.Log;
导入 com.google.android.maps.GeoPoint;
导入 com.google.android.maps.MapView;
导入 com.google.android.maps.Overlay;
导入 com.google.android.maps.Projection;
公共类 ROverlay 扩展覆盖 {
私有上下文上下文;
私有 HashMap 朋友位置;
私有 ArrayList locD;
私人位置位置;
私有 GeoPoint 位置点;
私人油漆油漆;
私人油漆背漆;
私有静态 int markerRadius = 7;
/** 获取当前位置 */
公共位置 getLocation() {
返回位置;
}
/** 设置当前位置 */
公共无效setLocation(位置位置){
this.location = 位置;
双纬= location.getLatitude()*1E6;
双经度 = location.getLongitude()*1E6;
locationPoint = new GeoPoint(latitude.intValue(),longitude.intValue());
}
/** 刷新每个联系人的位置 */
公共无效刷新位置(){
locD = RMapView.getARR();
}
/**
* 创建一个新的 FriendLocationOverlay 以在地图上显示您联系人的位置
* @param _context 父应用上下文
*/
公共ROverlay(上下文_context){
极好的();
上下文 = _上下文;
friendLocations = new HashMap();
locD = new ArrayList();
//刷新FriendLocations();
// 创建绘画对象
backPaint = new Paint();
backPaint.setARGB(200, 200, 200, 200);
backPaint.setAntiAlias(true);
油漆=新油漆();
油漆.setDither(true);
paint.setColor(Color.RED);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeJoin(Paint.Join.ROUND);
paint.setStrokeCap(Paint.Cap.ROUND);
油漆.setStrokeWidth(5);
}
@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
// 获取地图投影以将纬度/经度转换为屏幕坐标
投影投影 = mapView.getProjection();
for (int q = 1; q
【问题讨论】:
标签: android gps overlay android-mapview projection