0

How can I draw lines between different GPS coordinates to connect them all together?

I should mention that this is not a route. I am using satellite view and the line can go over a house for example.

Blubar
  • 71
  • 9

1 Answers1

0

If its just two coordinates than how about drawing a simple canvas over the map and drawing a straight line between those coordinates, so it would be a simple line and it could be any drawn anywhere , even over a house.

Below Sample Code was taken Drawing a line/path on Google Maps

/** Called when the activity is first created. */
 private List<Overlay> mapOverlays;

 private Projection projection;  

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

linearLayout = (LinearLayout) findViewById(R.id.zoomview);
mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);

mapOverlays = mapView.getOverlays();        
projection = mapView.getProjection();
mapOverlays.add(new MyOverlay());        

 }

@Override
 protected boolean isRouteDisplayed() {
return false;
 }

class MyOverlay extends Overlay{

public MyOverlay(){

}   

public void draw(Canvas canvas, MapView mapv, boolean shadow){
    super.draw(canvas, mapv, shadow);

    Paint   mPaint = new Paint();
    mPaint.setDither(true);
    mPaint.setColor(Color.RED);
    mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
    mPaint.setStrokeJoin(Paint.Join.ROUND);
    mPaint.setStrokeCap(Paint.Cap.ROUND);
    mPaint.setStrokeWidth(2);

    GeoPoint gP1 = new GeoPoint(19240000,-99120000);
    GeoPoint gP2 = new GeoPoint(37423157, -122085008);

    Point p1 = new Point();
    Point p2 = new Point();
    Path path = new Path();

    projection.toPixels(gP1, p1);
    projection.toPixels(gP2, p2);

    path.moveTo(p2.x, p2.y);
    path.lineTo(p1.x,p1.y);

    canvas.drawPath(path, mPaint);
}
Community
  • 1
  • 1
chossen-addict
  • 370
  • 1
  • 7
  • 31
  • Unfortunately it is not 2 coordinates.. more than that.. 30 maybe – Blubar Jan 24 '13 at 20:19
  • Do you know how can I set a button for this? which when i press that button it shows this one? – Blubar Jan 24 '13 at 21:17
  • you will just have to add a button in android and on click write this code mapOverlays.add(new MyOverlay()); instead of calling this before. – chossen-addict Jan 24 '13 at 21:31
  • the thing is in my extended Overlay class, I have another overlay (by usint onTap method).. so for this one I should define a separate class? – Blubar Jan 24 '13 at 21:51
  • Ok I put one other Overlay class inside my code and did as you said (mapOverlays.add(new MyOverlay()); ). npw when I click the button I wont get the line right away. I should touch the map, then the line will show up..why?! – Blubar Jan 24 '13 at 22:18
  • I guess the thing you are missing here is mapView.invalidate(); in onclick after adding new overlay. It will make sure to refresh any changes that happen in mapView. – chossen-addict Jan 24 '13 at 22:52