【问题标题】:Android MapView Projection returning negative numbersAndroid MapView Projection 返回负数
【发布时间】: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


    【解决方案1】:

    我不知道这个有什么问题。我无法让它工作,调试没有显示任何错误,所以最后我使用 Google Mytracks 项目中的代码来启用地图视图和投影问题

    http://code.google.com/p/mytracks/

    【讨论】:

      【解决方案2】:

      你应该看看这个 像素的投影值可能会有所不同。

      正如http://code.google.com/android/add-ons/google-apis/reference/com/google/android/maps/MapView.html#getProjection%28%29 所说,“地图在其当前状态下的投影。你不应该在这个对象上多画一次,因为地图的投影可能会改变。”

      而不是写

      projection.toPixels(geopoint2, point2); 
      

      你必须编码为

      mapView.getProjection().toPixels(geopoint2, point2); 
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-10-11
        • 2021-08-01
        相关资源
        最近更新 更多