android – 在Google地图上显示多个点之间的路线

我创建了自己的自定义地图,以显示我当前的位置和地图上的多个点.它工作正常,但现在我想显示从我当前位置到地图上每个点的路线.你能给我一些建议我怎么能这样做?谢谢.

这是我的customMap活动:

public class CustomMapActivity extends MapActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_map);

         String   provider = ""; 
         Criteria crit = new Criteria();
         Location loc = new Location("");
         LocationManager mlocManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

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

         List<Overlay> mapOverlays = mapView.getoverlays();
         Drawable drawable = this.getResources().getDrawable(R.drawable.marker);
         itemizedoverlayedClass itemizedoverlay = new itemizedoverlayedClass(drawable, this);

            try
            { 
             MyLocationOverlay mylocationOverlay = new MyLocationOverlay(this, mapView);
             mylocationOverlay.enableMyLocation();
             mapView.getoverlays().add(mylocationOverlay);          
             provider = mlocManager.getBestProvider(crit, false);
             loc = mlocManager.getLastKNownLocation(provider);
            }
            catch(Exception ex)
            {
            //Toast.makeText(this, "Unable to retrive provider", Toast.LENGTH_LONG).show();
            }


        for (ServiceActivity activity : DataSources.ActivitiesList)
        { 
            try
            {
                Location siteLocation =  new Location("");
                siteLocation.setLatitude(activity.SiteLatitude);
                siteLocation.setLongitude(activity.SiteLongitude);

                GeoPoint point = new GeoPoint((int)(activity.SiteLatitude * 1e6),(int)(activity.SiteLongitude * 1e6));
                OverlayItem overlayitem = new OverlayItem(point, activity.SiteName+ " " + activity.SiteAddress, "distance to this location: " + String.valueOf(loc.distanceto(siteLocation)/1000) + " km");

                itemizedoverlay.addOverlay(overlayitem);
                mapOverlays.add(itemizedoverlay);
            }
            catch(Exception ex)
            {
                @SuppressWarnings("unused")
                AlertDialogClass alert =  new AlertDialogClass(this,ex.getMessage());
            }
        }   




    }

    @Override
    protected void onResume() {
        // Todo Auto-generated method stub
        super.onResume();
        //mylocationOverlay.enableMyLocation();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_map, menu);
        return true;
    }

    @Override
    protected boolean isRoutedisplayed() {
        // Todo Auto-generated method stub
        return false;
    }


}

这是叠加类:

package com.example.srwebservice;


import java.util.ArrayList;

import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.Drawable;

import com.google.android.maps.itemizedoverlay;
import com.google.android.maps.OverlayItem;

public class itemizedoverlayedClass extends itemizedoverlay {

    private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
    Context mContext;

    public itemizedoverlayedClass(Drawable defaultMarker) 
    {
        super(boundCenterBottom(defaultMarker));
        // Todo Auto-generated constructor stub
    }

    public itemizedoverlayedClass(Drawable defaultMarker, Context context) 
    {
      super(boundCenterBottom(defaultMarker));
      mContext = context;
    }

    @Override
    protected OverlayItem createItem(int i) 
    {
        // Todo Auto-generated method stub
         return mOverlays.get(i);
    }

    @Override
    public int size()
    {
      return mOverlays.size();
    }

    public void addOverlay(OverlayItem overlay)
    {
        mOverlays.add(overlay);
        populate();
    }
    @Override
    protected boolean onTap(int index) {
      OverlayItem item = mOverlays.get(index);
      AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
      dialog.setTitle(item.getTitle());
      dialog.setMessage(item.getSnippet());
      dialog.show();
      return true;
    }
}

解决方法:

这个link有教程在我们的应用程序中绘制地图上的路径路径.这可能对你有帮助
使用下面的链接地图应用程序…这将在谷歌地图应用程序中

String uri = "http://maps.google.com/maps?f=d&hl=en&saddr="+source_latitude+","+source_longitude+"&daddr="+destination_latitude+","+destination_longitude;
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);

要么

重新链接链接how to display the driving routes

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...