android中的路径跟踪程序

android中的路径跟踪程序,android,android-intent,android-emulator,android-ndk,Android,Android Intent,Android Emulator,Android Ndk,我想要android中路径跟踪程序的源代码。 我看到了代码 公共void绘图路径(NavigationDataSet导航集,int-color,MapView mMapView01){ Log.d(myapp.APP,“映射颜色前:”+color); //用餐时进行颜色校正,使其颜色更暗 如果(color==color.parseColor(#add331”))color=color.parseColor(#6C8715”); Log.d(myapp.APP,“地图颜色在“+颜色”之后); Co

我想要android中路径跟踪程序的源代码。 我看到了代码 公共void绘图路径(NavigationDataSet导航集,int-color,MapView mMapView01){

Log.d(myapp.APP,“映射颜色前:”+color);
//用餐时进行颜色校正,使其颜色更暗
如果(color==color.parseColor(#add331”))color=color.parseColor(#6C8715”);
Log.d(myapp.APP,“地图颜色在“+颜色”之后);
Collection OverlyLoadDagain=new ArrayList();
for(迭代器iter=mMapView01.getOverlays().Iterator();iter.hasNext();){
对象o=iter.next();
Log.d(myapp.APP,“覆盖类型:+o.getClass().getName());
如果(!RouteOverlay.class.getName().equals(o.getClass().getName())){
//mMapView01.getOverlays().remove(o);
加上(o);
}
}
mMapView01.getOverlays().clear();
mMapView01.getOverlays().addAll(overlaysToAddAgain);
字符串路径=navSet.getRoutePlacemark().getCoordinates();
Log.d(myapp.APP,“path=“+path”);
if(path!=null&&path.trim().length()>0){
String[]pairs=path.trim().split(“”);
Log.d(myapp.APP,“pairs.length=“+pairs.length”);
字符串[]lngLat=pairs[0]。拆分(“,”;//lngLat[0]=经度lngLat[1]=纬度lngLat[2]=高度
Log.d(myapp.APP,“lnglat=“+lnglat+”,长度:“+lnglat.length”);
如果(lngLat.length=2&&gp1.getLatitudeE6()>0&&gp1.getLongtudee6()>0
&&gp2.getLatitudeE6()>0&&gp2.getLongitudeE6()>0){
//对于地质点,第一个:纬度,第二个:经度
gp2=新的地质点((int)(Double.parseDouble(lngLat[1])*1E6),(int)(Double.parseDouble(lngLat[0])*1E6));
如果(gp2.getLatitudeE6()!=22200000){
mMapView01.getOverlays().add(新路由覆盖(gp1、gp2、2、颜色));
Log.d(myapp.APP,“绘图:”+gp1.getLatitudeE6()+“/”+gp1.getLongitudeE6()+”到“+gp2.getLatitudeE6()+”/”+gp2.getLongitudeE6()”);
}
}
//Log.d(myapp.APP,“pair:+pairs[i]);
}
//添加(新的RouteOverlay(gp2,gp2,3));
mMapView01.getOverlays().add(新路由覆盖(gp2,gp2,3));
}捕获(数字格式){
Log.e(myapp.APP,“无法绘制路线”,e);
}
}
//mMapView01.getOverlays().addAll(routeOverlays);//使用默认颜色
mMapView01.setEnabled(true);
} 但我无法执行代码。 如果你不介意的话,可以给任何一次完整的源代码


谢谢。

我有两门课HomeActivity和MyOverlay在谷歌地图上绘制路径 以下是家庭活动:

MapView mapView;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Log.e("Home", " activity created");
    mapView = (MapView) findViewById(R.id.mapview);
    double src_lat = 28.011022; // the testing source  28.011022,73.323802
    double src_long = 73.323802;
    double dest_lat = 28.008389; // the testing destination   28.008389,73.33599
    double dest_long = 73.33599;

    Log.e("Home ", " Strting drawing path");
    GeoPoint srcGeoPoint = new GeoPoint((int) (src_lat * 1E6),
            (int) (src_long * 1E6));
    GeoPoint destGeoPoint = new GeoPoint((int) (dest_lat * 1E6),
            (int) (dest_long * 1E6));
    Log.e("Home ", " Strting drawing path");

    List<Overlay> mapOverlays = mapView.getOverlays();
    Drawable drawable = this.getResources().getDrawable(R.drawable.darkgreen_marker);
    mapView.getOverlays();
    OverlayItem overlayitem = new OverlayItem(srcGeoPoint, "Hello!", "This is your position");
    overLay marker_overlay=new overLay(drawable);
    marker_overlay.addOverlay(overlayitem);
    mapOverlays.add(marker_overlay);
    overlayitem = new OverlayItem(destGeoPoint, "Theater Big ", "Go to this ");
    marker_overlay.addOverlay(overlayitem);
    mapOverlays.add(marker_overlay);
    //mapView.getOverlays().add(new overLay(null, destGeoPoint));

    DrawPath(srcGeoPoint, destGeoPoint, Color.GREEN, mapView);      
    mapView.getController().animateTo(srcGeoPoint);
    mapView.getController().setZoom(15);
    mapView.setBuiltInZoomControls(true);
}

@Override
protected boolean isRouteDisplayed() {

    return false;
}

private void DrawPath(GeoPoint src,GeoPoint dest, int color, MapView mMapView01)
{
    // connect to map web service
    StringBuilder urlString = new StringBuilder();
    urlString.append("http://maps.google.com/maps?f=d&hl=en");
    urlString.append("&saddr=");//from
    urlString.append( Double.toString((double)src.getLatitudeE6()/1.0E6 ));
    urlString.append(",");
    urlString.append( Double.toString((double)src.getLongitudeE6()/1.0E6 ));
    urlString.append("&daddr=");//to
    urlString.append( Double.toString((double)dest.getLatitudeE6()/1.0E6 ));
    urlString.append(",");
    urlString.append( Double.toString((double)dest.getLongitudeE6()/1.0E6 ));
    urlString.append("&ie=UTF8&0&om=0&output=kml");
    Log.e("Draw path  ","URL="+urlString.toString());
    // get the kml (XML) doc. And parse it to get the coordinates(direction route).
    Document doc = null;

    HttpURLConnection urlConnection= null;
    URL url = null;
    try
    {
        url = new URL(urlString.toString());
        urlConnection=(HttpURLConnection)url.openConnection();
        urlConnection.setRequestMethod("GET");
        urlConnection.setDoOutput(true);
        urlConnection.setDoInput(true);
        urlConnection.connect();

        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        doc = db.parse(urlConnection.getInputStream());
        Log.e(" Home ", " response"+doc.toString());
        if(doc.getElementsByTagName("GeometryCollection").getLength()>0)
        {
            //String path = doc.getElementsByTagName("GeometryCollection").item(0).getFirstChild().getFirstChild().getNodeName();
            String path = doc.getElementsByTagName("GeometryCollection").item(0).getFirstChild().getFirstChild().getFirstChild().getNodeValue() ;
            Log.d("draw path ","path="+ path);
            String [] pairs = path.split(" ");
            String[] lngLat = pairs[0].split(","); // lngLat[0]=longitude lngLat[1]=latitude lngLat[2]=height
            // src
            GeoPoint startGP = new GeoPoint((int)(Double.parseDouble(lngLat[1])*1E6),(int)(Double.parseDouble(lngLat[0])*1E6));
            mMapView01.getOverlays().add(new MyOverLay(startGP,startGP,1));
            GeoPoint gp1;
            GeoPoint gp2 = startGP;
            for(int i=1;i<pairs.length;i++) // the last one would be crash
            {
                lngLat = pairs[i].split(",");
                gp1 = gp2;
                // watch out! For GeoPoint, first:latitude, second:longitude
                gp2 = new GeoPoint((int)(Double.parseDouble(lngLat[1])*1E6),(int)(Double.parseDouble(lngLat[0])*1E6));
                mMapView01.getOverlays().add(new MyOverLay(gp1,gp2,2,color));
                Log.d("Draw path","pair:" + pairs[i]);
            }
            mMapView01.getOverlays().add(new MyOverLay(dest,dest, 3)); // use the default color
        }
    }catch (MalformedURLException e){
        e.printStackTrace();
    }
    catch (IOException e){
        e.printStackTrace();
    }
    catch (ParserConfigurationException e){
        e.printStackTrace();
    }
    catch (SAXException e){
        e.printStackTrace();
    }
}

public class overLay extends ItemizedOverlay<OverlayItem>{
    private List<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
    GeoPoint gp1;
    Drawable marker;

    public overLay(Drawable marker) {
        super(marker);
        this.marker=marker;
    }

    public void addOverlay(OverlayItem overlay){
        mOverlays.add(overlay);
        Log.e(" Map Overlay __", " adding new item "+overlay);
        populate();
    }

    @Override
    public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when){
        Projection projection = mapView.getProjection();
        Point point = new Point();
        for(int i=0;i<mOverlays.size();i++){
            OverlayItem g = getItem(i);
            gp1=g.getPoint();
            projection.toPixels(gp1, point);
              Bitmap bmp = BitmapFactory.decodeResource(
                        getResources(), R.drawable.marker_red);            
                    canvas.drawBitmap(bmp, point.x-10, point.y-35, null);
        }
        return super.draw(canvas, mapView, shadow, when);
    }

    @Override
    public boolean onTap(int index){
        /* GeoPonit p MapView mapView*/
        OverlayItem item = getItem(index);
        GeoPoint gp=item.getPoint();
        String msg=item.getSnippet();

        mapView.getController().animateTo(gp);
        Log.e("-- map view --", " marker clicked "+gp);

        LayoutInflater infalter=getLayoutInflater();
        final LinearLayout table = (LinearLayout)infalter.inflate(R.layout.popup_baloon_layout, null);  
        table.setWillNotDraw(false);
        final MapView.LayoutParams lp2 = new MapView.LayoutParams(
                150,100,gp,-15,-10,MapView.LayoutParams.BOTTOM_CENTER);  
        TextView addrs=(TextView)table.findViewById(R.id.address);
        addrs.setText(msg);
        ImageView call_img=(ImageView)table.findViewById(R.id.imageView1);
        call_img.setOnClickListener(new OnClickListener() {
            @Override 
            public void onClick(View v) {
                Log.e("__ Home __", " making call to 12345");
                Bundle bundle=new Bundle();
                mapView.removeView(table);
                Intent intent = new Intent(Intent.ACTION_CALL);
                intent.setData(Uri.parse("tel:" + bundle.getString("12345")));
                HomeActivity.this.startActivity(intent);

            }
        });

        table.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                mapView.removeView(table);
                //table=null;
            }
        });

        mapView.addView(table,lp2);
        return true;
    }

    @Override
    protected OverlayItem createItem(int i) {
        Log.e("Map Overlay __", " creating overlay item "+i);
        return mOverlays.get(i);
    }

    @Override
    public int size() {
        Log.e("Map Overlay __", " getting overlay size ");
        return mOverlays.size();
    }

}
}


这些类使用kml在两个位置之间绘制路径。

android.app.ActionBar未解析。ListenusingSecureRfcommWithServiceRecord(NAME\u Unsecure,MY\u UUID\u Unsecure)此方法未定义。我的要求是,当用户启动应用程序时,它每5秒保存一次经度和纬度。到达目的地后,应用程序使用保存的经度和纬度绘制地图。可能吗?谢谢advanced@venkat然后您只需修改HomeActivity类中的DrawPath()函数,只需使用
mMapView01.getOverlays().add(new MyOverLay(dest,dest,3))
并从DrawPath()中删除其余代码我是android新手。因此,如果我尝试在该站点中执行代码,它会给我带来很多错误。如果你不介意给我整个应用程序,那么我将在我的系统中测试,然后修改它。请理解我的问题。我很久以前下载了这个示例,没有链接。。我可以通过邮件向您发送整个示例
MapView mapView;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Log.e("Home", " activity created");
    mapView = (MapView) findViewById(R.id.mapview);
    double src_lat = 28.011022; // the testing source  28.011022,73.323802
    double src_long = 73.323802;
    double dest_lat = 28.008389; // the testing destination   28.008389,73.33599
    double dest_long = 73.33599;

    Log.e("Home ", " Strting drawing path");
    GeoPoint srcGeoPoint = new GeoPoint((int) (src_lat * 1E6),
            (int) (src_long * 1E6));
    GeoPoint destGeoPoint = new GeoPoint((int) (dest_lat * 1E6),
            (int) (dest_long * 1E6));
    Log.e("Home ", " Strting drawing path");

    List<Overlay> mapOverlays = mapView.getOverlays();
    Drawable drawable = this.getResources().getDrawable(R.drawable.darkgreen_marker);
    mapView.getOverlays();
    OverlayItem overlayitem = new OverlayItem(srcGeoPoint, "Hello!", "This is your position");
    overLay marker_overlay=new overLay(drawable);
    marker_overlay.addOverlay(overlayitem);
    mapOverlays.add(marker_overlay);
    overlayitem = new OverlayItem(destGeoPoint, "Theater Big ", "Go to this ");
    marker_overlay.addOverlay(overlayitem);
    mapOverlays.add(marker_overlay);
    //mapView.getOverlays().add(new overLay(null, destGeoPoint));

    DrawPath(srcGeoPoint, destGeoPoint, Color.GREEN, mapView);      
    mapView.getController().animateTo(srcGeoPoint);
    mapView.getController().setZoom(15);
    mapView.setBuiltInZoomControls(true);
}

@Override
protected boolean isRouteDisplayed() {

    return false;
}

private void DrawPath(GeoPoint src,GeoPoint dest, int color, MapView mMapView01)
{
    // connect to map web service
    StringBuilder urlString = new StringBuilder();
    urlString.append("http://maps.google.com/maps?f=d&hl=en");
    urlString.append("&saddr=");//from
    urlString.append( Double.toString((double)src.getLatitudeE6()/1.0E6 ));
    urlString.append(",");
    urlString.append( Double.toString((double)src.getLongitudeE6()/1.0E6 ));
    urlString.append("&daddr=");//to
    urlString.append( Double.toString((double)dest.getLatitudeE6()/1.0E6 ));
    urlString.append(",");
    urlString.append( Double.toString((double)dest.getLongitudeE6()/1.0E6 ));
    urlString.append("&ie=UTF8&0&om=0&output=kml");
    Log.e("Draw path  ","URL="+urlString.toString());
    // get the kml (XML) doc. And parse it to get the coordinates(direction route).
    Document doc = null;

    HttpURLConnection urlConnection= null;
    URL url = null;
    try
    {
        url = new URL(urlString.toString());
        urlConnection=(HttpURLConnection)url.openConnection();
        urlConnection.setRequestMethod("GET");
        urlConnection.setDoOutput(true);
        urlConnection.setDoInput(true);
        urlConnection.connect();

        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        doc = db.parse(urlConnection.getInputStream());
        Log.e(" Home ", " response"+doc.toString());
        if(doc.getElementsByTagName("GeometryCollection").getLength()>0)
        {
            //String path = doc.getElementsByTagName("GeometryCollection").item(0).getFirstChild().getFirstChild().getNodeName();
            String path = doc.getElementsByTagName("GeometryCollection").item(0).getFirstChild().getFirstChild().getFirstChild().getNodeValue() ;
            Log.d("draw path ","path="+ path);
            String [] pairs = path.split(" ");
            String[] lngLat = pairs[0].split(","); // lngLat[0]=longitude lngLat[1]=latitude lngLat[2]=height
            // src
            GeoPoint startGP = new GeoPoint((int)(Double.parseDouble(lngLat[1])*1E6),(int)(Double.parseDouble(lngLat[0])*1E6));
            mMapView01.getOverlays().add(new MyOverLay(startGP,startGP,1));
            GeoPoint gp1;
            GeoPoint gp2 = startGP;
            for(int i=1;i<pairs.length;i++) // the last one would be crash
            {
                lngLat = pairs[i].split(",");
                gp1 = gp2;
                // watch out! For GeoPoint, first:latitude, second:longitude
                gp2 = new GeoPoint((int)(Double.parseDouble(lngLat[1])*1E6),(int)(Double.parseDouble(lngLat[0])*1E6));
                mMapView01.getOverlays().add(new MyOverLay(gp1,gp2,2,color));
                Log.d("Draw path","pair:" + pairs[i]);
            }
            mMapView01.getOverlays().add(new MyOverLay(dest,dest, 3)); // use the default color
        }
    }catch (MalformedURLException e){
        e.printStackTrace();
    }
    catch (IOException e){
        e.printStackTrace();
    }
    catch (ParserConfigurationException e){
        e.printStackTrace();
    }
    catch (SAXException e){
        e.printStackTrace();
    }
}

public class overLay extends ItemizedOverlay<OverlayItem>{
    private List<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
    GeoPoint gp1;
    Drawable marker;

    public overLay(Drawable marker) {
        super(marker);
        this.marker=marker;
    }

    public void addOverlay(OverlayItem overlay){
        mOverlays.add(overlay);
        Log.e(" Map Overlay __", " adding new item "+overlay);
        populate();
    }

    @Override
    public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when){
        Projection projection = mapView.getProjection();
        Point point = new Point();
        for(int i=0;i<mOverlays.size();i++){
            OverlayItem g = getItem(i);
            gp1=g.getPoint();
            projection.toPixels(gp1, point);
              Bitmap bmp = BitmapFactory.decodeResource(
                        getResources(), R.drawable.marker_red);            
                    canvas.drawBitmap(bmp, point.x-10, point.y-35, null);
        }
        return super.draw(canvas, mapView, shadow, when);
    }

    @Override
    public boolean onTap(int index){
        /* GeoPonit p MapView mapView*/
        OverlayItem item = getItem(index);
        GeoPoint gp=item.getPoint();
        String msg=item.getSnippet();

        mapView.getController().animateTo(gp);
        Log.e("-- map view --", " marker clicked "+gp);

        LayoutInflater infalter=getLayoutInflater();
        final LinearLayout table = (LinearLayout)infalter.inflate(R.layout.popup_baloon_layout, null);  
        table.setWillNotDraw(false);
        final MapView.LayoutParams lp2 = new MapView.LayoutParams(
                150,100,gp,-15,-10,MapView.LayoutParams.BOTTOM_CENTER);  
        TextView addrs=(TextView)table.findViewById(R.id.address);
        addrs.setText(msg);
        ImageView call_img=(ImageView)table.findViewById(R.id.imageView1);
        call_img.setOnClickListener(new OnClickListener() {
            @Override 
            public void onClick(View v) {
                Log.e("__ Home __", " making call to 12345");
                Bundle bundle=new Bundle();
                mapView.removeView(table);
                Intent intent = new Intent(Intent.ACTION_CALL);
                intent.setData(Uri.parse("tel:" + bundle.getString("12345")));
                HomeActivity.this.startActivity(intent);

            }
        });

        table.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                mapView.removeView(table);
                //table=null;
            }
        });

        mapView.addView(table,lp2);
        return true;
    }

    @Override
    protected OverlayItem createItem(int i) {
        Log.e("Map Overlay __", " creating overlay item "+i);
        return mOverlays.get(i);
    }

    @Override
    public int size() {
        Log.e("Map Overlay __", " getting overlay size ");
        return mOverlays.size();
    }

}
public class MyOverLay extends Overlay{
private GeoPoint gp1;
private GeoPoint gp2;
//private int mRadius=6;
private int mode=0;
private int defaultColor;
//private String text="";
//private Bitmap img = null;
private Context context;

public MyOverLay(GeoPoint gp1,GeoPoint gp2,int mode,Context context){// GeoPoint is a int. (6E)
    this.gp1 = gp1;
    this.gp2 = gp2;
    this.mode = mode;
    defaultColor = 999; // no defaultColor
    this.context=context;
}

public MyOverLay(GeoPoint gp1,GeoPoint gp2,int mode, int defaultColor,Context context){
    this.gp1 = gp1;
    this.gp2 = gp2;
    this.mode = mode;
    this.defaultColor = defaultColor;
    this.context=context;
}

/*public void setText(String t){
    this.text = t;
}

public void setBitmap(Bitmap bitmap){
    this.img = bitmap;
}*/

public int getMode(){
    return mode;
}

@Override
public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when){
    Projection projection = mapView.getProjection();
    if (shadow == false){
        Paint paint = new Paint();
        paint.setAntiAlias(true);
        Point point = new Point();
        projection.toPixels(gp1, point);
        // mode=1&#65306;start
        if(mode==1){
            if(defaultColor==999)
            paint.setColor(Color.BLUE);
            else
            paint.setColor(defaultColor);
            Bitmap bmp = BitmapFactory.decodeResource(
                    context.getResources(), R.drawable.marker_red);            
                canvas.drawBitmap(bmp, point.x-10, point.y-35, null);

            /*RectF oval=new RectF(point.x - mRadius, point.y - mRadius,
            point.x + mRadius, point.y + mRadius);*/
            // start point
            //canvas.drawOval(oval, paint);
        }
        // mode=2&#65306;path
        else if(mode==2){
            if(defaultColor==999)
            paint.setColor(Color.RED);
            else
            paint.setColor(defaultColor);
            Point point2 = new Point();
            projection.toPixels(gp2, point2);
            paint.setStrokeWidth(5);
            paint.setAlpha(120);
            canvas.drawLine(point.x, point.y, point2.x,point2.y, paint);
        }
        /* mode=3&#65306;end */
        else if(mode==3){
        /* the last path */

            if(defaultColor==999)
            paint.setColor(Color.GREEN);
            else
            paint.setColor(defaultColor);
            Point point2 = new Point();
            projection.toPixels(gp2, point2);
            paint.setStrokeWidth(5);
            paint.setAlpha(120);
            canvas.drawLine(point.x, point.y, point2.x,point2.y, paint);
            Bitmap bmp = BitmapFactory.decodeResource(
                    context.getResources(), R.drawable.marker_red);            
                canvas.drawBitmap(bmp, point.x-16, point.y-38, null);
            /*RectF oval=new RectF(point2.x - mRadius,point2.y - mRadius,
            point2.x + mRadius,point2.y + mRadius);
            paint.setAlpha(255);
            canvas.drawOval(oval, paint);*/
        }
    }
    return super.draw(canvas, mapView, shadow, when);
}

@Override
public boolean onTap(GeoPoint p, MapView mapView){

    return false;
}