0

I am a newbie in android field. I have written a android App1 that will retrieve latitude and longitude values from Network Provider and stores it in my local server(LAMP).

I have also created a MYSQL DB table that has 3 columns(lat,lon,id) that has the values (lat and lon) which are retrieved using the Network Provider. Currently there are more than 10 values in my table.

I have created JSON object for getting those values from MYSQL DB using PHP script in my Android App2. All these things works fine. I have also done creating MapActivity which will plot those lat and lon values on map using Marker.

What I have to do now is to join those markers to draw path on google map. How to do it. Please help

Ricky Khatri
  • 952
  • 2
  • 16
  • 42
user1917865
  • 51
  • 1
  • 8

2 Answers2

3

Try this.

String uri = "http://maps.google.com/maps?saddr=" + currentLatitude+","+currentLongitude+"&daddr="+fixedLatitude+","+fixedLongitude;
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);

may this help you

Pankaj Singh
  • 2,241
  • 2
  • 16
  • 16
  • I tried it.. It is working fine.. But what I need to do is to just join the markers to show the route traveled by joining lines.. It is showing the Driving direction automatically and not the route through which we traveled rite ?? If I am wrong please correct me.. – user1917865 Dec 27 '12 at 07:33
  • have look to this [http://stackoverflow.com/questions/3109158/how-to-draw-a-path-on-a-map-using-kml-file/3109723#3109723] – Pankaj Singh Dec 27 '12 at 08:47
1

Try this this to draw path in google map

public class Location extends MapActivity {
MapView mapView;
public static ArrayList<String> paramLat = new ArrayList<String>();
public static ArrayList<String> paramLong = new ArrayList<String>();
private List<Overlay> mapOverlays;
public List<GeoPoint> geopoints = new ArrayList<GeoPoint>();
public void onCreate(Bundle savedInstanceState) {

//your code to display location

for(int i=0;i<paramLat.size();i++)
        {
            lat = Double.parseDouble(paramLat.get(i)); 
            lon = Double.parseDouble(paramLong.get(i));
            geoPoint = new GeoPoint((int)(lat * 1E6), (int)(lon *1E6));
            geopoints.add(geoPoint);
           }

mapOverlays = mapView.getOverlays();
mapOverlays.add(new MyOverlay());
}

class MyOverlay extends Overlay{

    public MyOverlay(){

    }   

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

        int loopcount = geopoints.size() - 1; 
        Paint   mPaint = new Paint();
        mPaint.setDither(true);
        mPaint.setColor(Color.BLUE);
        mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
        mPaint.setStrokeJoin(Paint.Join.ROUND);
        mPaint.setStrokeCap(Paint.Cap.ROUND);
        mPaint.setStrokeWidth(2);
        for (int i = 0; i < loopcount; i++) 
        {
            GeoPoint pp1 = (GeoPoint) geopoints.get(i);
            GeoPoint pp2 = (GeoPoint) geopoints.get(i + 1);
            Point p1 = new Point();
            Point p2 = new Point();
            Path path = new Path();

            projection.toPixels(pp1, p1);
            projection.toPixels(pp2, p2);

            path.moveTo(p2.x, p2.y);
            path.lineTo(p1.x,p1.y);
            canvas.drawPath(path, mPaint);
        }
    }
   }  //end of MyOverlay class
}  //end of Location class
Dhana
  • 554
  • 1
  • 9
  • 29