Call below RetreiveFeedTask.class like this..
String url = "http://routes.cloudmade.com/A6421860EBB04234AB5EF2D049F2CD8F/api/0.3/"
+ mLatitude_Current+ ","
+ mLongitude_Current+","
+ mLatitude_Place+ ","
+ mLongitude_Place + "/car.gpx";
new RetreiveFeedTask(ActivityMapDrawPath.this, MapView, MapView.getOverlays(), mGeoPoint_Current).execute(url);
RetreiveFeedTask.class
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import android.app.Activity;
import android.app.ProgressDialog;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Point;
import android.os.AsyncTask;
import android.widget.Toast;
import androidexperts.app.gujrattourism.parser.ParserRouteDetails;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
public class RetreiveFeedTask extends AsyncTask
private ProgressDialog dialog;
Activity mActivity;
ArrayList
public ParserRouteDetails mXMLGetterSetter;
MapView mMapView;
List
MapOverlay mapOverlay;
GeoPoint mGeoPoint_Current;
public RetreiveFeedTask(Activity mActivity,MapView mMapView,List
this.mActivity = mActivity;
this.mMapView = mMapView;
this.mListOverlay = mListOverlay;
this.mGeoPoint_Current = mGeoPoint_Current;
dialog = new ProgressDialog(mActivity);
}
protected Void doInBackground(String... urls) {
try {
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
XMLParserHandler myXMLHandler = new XMLParserHandler();
xr.setContentHandler(myXMLHandler);
URL url = new URL(urls[0]);
itemsList = myXMLHandler.getItemsArrayList();
xr.parse(new InputSource(url.openStream()));
return null;
} catch (Exception e) {
return null;
}
}
@Override
protected void onPreExecute() {
super.onPreExecute();
this.dialog.setMessage("Loading...");
this.dialog.show();
}
protected void onPostExecute(Void feed) {
mMapView.invalidate();
if (dialog.isShowing())
dialog.dismiss();
if(itemsList.size() > 0){
mapOverlay = new MapOverlay(mGeoPoint_Current);
mListOverlay.add(mapOverlay);
}else{
Toast.makeText(mActivity, "Path not Found......", Toast.LENGTH_SHORT).show();
}
}
public class MapOverlay extends com.google.android.maps.Overlay {
int check_id;
public MapOverlay(GeoPoint mGeoPoint) {
}
@Override
public boolean draw(final Canvas canvas, MapView mapView, boolean shadow, long when) {
Point mpoint = new Point();
Point mpoint1 = new Point();
GeoPoint firstGeoPoint = null;
GeoPoint secondGeoPoint = null;
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
// if(itemsList.size() > 0){
for (int i = 0; i < itemsList.size(); i++) {
mXMLGetterSetter = itemsList.get(i);
if (i < (itemsList.size() - 1)) {
firstGeoPoint = new GeoPoint(
(int)(Double.parseDouble(itemsList.get(i).getLatitude())*1E6),
(int)(Double.parseDouble(itemsList.get(i).getLongitude())*1E6));
secondGeoPoint = new GeoPoint(
(int)(Double.parseDouble(itemsList.get(i+1).getLatitude())*1E6),
(int)(Double.parseDouble(itemsList.get(i+1).getLongitude())*1E6));
paint.setDither(true);
paint.setColor(Color.parseColor("#562302"));
paint.setStyle(Paint.Style.FILL_AND_STROKE);
paint.setStrokeJoin(Paint.Join.ROUND);
paint.setStrokeWidth(100);
paint.setStrokeCap(Paint.Cap.ROUND);
Path path = new Path();
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(7f);
mapView.getProjection().toPixels(firstGeoPoint, mpoint);
mapView.getProjection().toPixels(secondGeoPoint, mpoint1);
path.moveTo(mpoint1.x, mpoint1.y);
path.lineTo(mpoint.x, mpoint.y);
canvas.drawPath(path, paint);
}
}
// }else{
// Toast.makeText(mActivity, "Path not Found......", Toast.LENGTH_SHORT).show();
// }
return false;
}
}
}
No comments:
Post a Comment