1

I've been working on this for a while now, but I still have not gotten the result I'm looking for. I'm trying to create an app to display our mountain bike trails so you can see where you are when you're on them. I started by manually copying coordinates from my kml file and pasting them as Geopoints with this code which worked until I got to point 80. Then the LogCat gave an error rejecting large method, and I still have hundreds more to go:

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;  
    }
}

Then I tried to parse the kml file as in this example: How to draw a path on a map using kml file?

But this is taking my coordinates and finding the nearest streets and overlaying a route. My coordinates are not along the street they are in a park off road, so how else should I do it?

Right now I'm open to any suggestions. Is there a better way to parse the kml file, do it locally vs going to http://maps.google.com/maps?, overlaying it as an image, or a whole new direction completely... Any suggestions would be much appreciated.

Thanks

Community
  • 1
  • 1
Lars Hovden
  • 317
  • 2
  • 25
  • I've imported the kml file into My Google Maps. Is there a way to overlay that so it can be seen by other people more than myself? – Lars Hovden Aug 21 '12 at 22:28
  • This is already answered here on stackoverflow, please check http://stackoverflow.com/questions/3109158/how-to-draw-a-path-on-a-map-using-kml-file/3109723#3109723 – Yashpal Singla Mar 09 '13 at 14:28

0 Answers0