1

我已经为此工作了一段时间,但我仍然没有得到我正在寻找的结果。我正在尝试创建一个应用程序来显示我们的山地自行车道,以便您在骑行时可以看到自己的位置。我首先从我的 kml 文件中手动复制坐标,然后使用此代码将它们粘贴为 Geopoints,该代码一直有效,直到我到达 80 点。然后 LogCat 给出了拒绝大方法的错误,我还有数百个方法要做:

import java.util.List;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Point;
import android.os.Bundle;

public class TrailMaps extends  MapActivity  {
    private List mapOverlays;
    private Projection projection;
    private MapController mc;
    private MapView mapView;
    private GeoPoint gP;
    private MyOverlay myoverlay;

    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);    
    mapView = (MapView) findViewById(R.id.mapview);//Creating an instance of MapView
    mapView.setBuiltInZoomControls(true);//Enabling the built-in Zoom Controls
    gP = new GeoPoint(43311836,-91777756);//Creating a GeoPoint
    mc = mapView.getController();
    mc.setCenter(gP);
    mc.setZoom(15);//Initializing the MapController and setting the map to center at the
    mapOverlays = mapView.getOverlays();
    projection = mapView.getProjection();
    myoverlay = new MyOverlay();
    mapOverlays.add(myoverlay);
    }

    class MyOverlay extends Overlay{ 
        public MyOverlay(){      
        }                     
      public void draw(Canvas canvas, MapView mapView, boolean shadow) {
         super.draw(canvas, mapView, shadow);
         Paint paint;
         paint = new Paint();
         paint.setDither(true);
         paint.setColor(Color.RED);
         paint.setStyle(Paint.Style.FILL_AND_STROKE);
         paint.setStrokeJoin(Paint.Join.ROUND);
         paint.setStrokeWidth(2);        

         GeoPoint gp1 = new GeoPoint(43311836,-91777756);
         GeoPoint gp2 = new GeoPoint(43311718,-91777699);
         GeoPoint gp3 = new GeoPoint(43311718,-91777699);
         GeoPoint gp4 = new GeoPoint(43311666,-91777627);
         GeoPoint gp5 = new GeoPoint(43311624,-91777541);                    

         Point pt1 = new Point();
         Point pt2 = new Point();
         Point pt3 = new Point();
         Point pt4 = new Point();
         Point pt5 = new Point();

         Path path1 = new Path();
         Path path2 = new Path();
         Path path3 = new Path();

         projection.toPixels(gp1,pt1);
         projection.toPixels(gp2, pt2);
         projection.toPixels(gp3, pt3);
         projection.toPixels(gp4, pt4);
         projection.toPixels(gp5, pt5);

         path1.moveTo(pt1.x, pt1.y);
         path1.lineTo(pt2.x, pt2.y);         
         path2.moveTo(pt3.x,pt3.y);
         path2.lineTo(pt4.x, pt4.y);         
         path3.moveTo(pt4.x,pt4.y);
         path3.lineTo(pt5.x,pt5.y);                               

         canvas.drawPath(path1, paint);
         canvas.drawPath(path2, paint);  
         canvas.drawPath(path3, paint);               
      }
   }
   @Override
   protected boolean isRouteDisplayed() {          
      return false;  
    }
}

然后我尝试解析 kml 文件,如下例所示:如何使用 kml 文件在地图上绘制路径?

但这是在获取我的坐标并找到最近的街道并覆盖一条路线。我的坐标不在街道上,而是在路边的公园里,那我该怎么做呢?

现在我愿意接受任何建议。有没有更好的方法来解析 kml 文件,在本地进行而不是去http://maps.google.com/maps?,将其作为图像覆盖,或者完全是一个全新的方向......任何建议都会很多赞赏。

谢谢

4

0 回答 0