0

I'm refering to this post

I get an exception, so I tried using AsyncTask like the last answer in this post . Now the application is running whitout any exception, but it don't draw a path. I don't know what is the problem.

Here is the code :http://www.mediafire.com/?lxm7gplzsfdtsx5 I just replace itineraire.java with MainActivity.java below

public class MainActivity extends MapActivity {

MapView mapView = null;
MapController mapController;
double long1 = 50.123*1E6;
double lati1 = 13.123*1E6;
double long2 = 50.221*1E6;
double lati2 = 13.221*1E6;
GeoPoint start, dest;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_itineraire);
    mapView = (MapView) findViewById(R.id.mapView);
    mapView.setBuiltInZoomControls(true);


     DirectionsTask getDirectionsTask = new DirectionsTask();
     getDirectionsTask.execute(new GeoPoint((int)(long1),(int)(lati1)), new GeoPoint((int)(long2),(int)(lati2)));



 }

private class DirectionsTask extends AsyncTask<GeoPoint, Void, Route> {

protected Route doInBackground(GeoPoint...geoPoints) {
    start = geoPoints[0];
    dest =  geoPoints[1];

       Parser parser;
        String jsonURL = "http://maps.google.com/maps/api/directions/json?";
        final StringBuffer sBuf = new StringBuffer(jsonURL);
        sBuf.append("origin=");
        sBuf.append(start.getLatitudeE6()/1E6);
        sBuf.append(',');
        sBuf.append(start.getLongitudeE6()/1E6);
        sBuf.append("&destination=");
        sBuf.append(dest.getLatitudeE6()/1E6);
        sBuf.append(',');
        sBuf.append(dest.getLongitudeE6()/1E6);
        sBuf.append("&sensor=true&mode=driving");
        Log.v("I came in URL", sBuf.toString());
        parser = new GoogleParser(sBuf.toString());
        Route r =  parser.parse();
        return r;
}




 protected void onPostExecute(Route route) {
    RouteOverlay routeOverlay = new RouteOverlay(route, Color.BLUE);
    mapView.getOverlays().add(routeOverlay);
    mapView.invalidate();
    mapController = mapView.getController();
    mapController.setZoom(14);
    mapView.getMapCenter();
}

}

@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
Community
  • 1
  • 1
sara
  • 427
  • 1
  • 6
  • 8

1 Answers1

0

Your route is drawn on the map but it is off the screen if you move the map you will find your route drawn, I would suggest to use the new Maps API which is much better and easier to draw the route on the map.

with the current implementation you can use mapView.getController().zoomToSpan((int)lati1,(int)long1); to center your map to that giving point

Moh Sakkijha
  • 2,705
  • 1
  • 14
  • 19
  • I changed the Map API and added this line. so how can I get the route on the screen ? – sara Jan 05 '13 at 01:41
  • check this link it will show you how to draw a line on the map https://developers.google.com/maps/documentation/android/lines , there is no need for an overlay, just create the polyline and add it to the map as described. – Moh Sakkijha Jan 05 '13 at 08:39
  • Thanks so much, I'm trying with this – sara Jan 05 '13 at 23:56