android 高德地图 驾车路线规划
来源:互联网 发布:天天直播网络东方卫视 编辑:程序博客网 时间:2024/04/28 08:44
在此贴出高德地图驾车路线规划(导航) 其它引用到的类请自行到官方下载演示demo进行配置 ,希望能帮到有需要的人.
-----------------------------------------------无敌分割线------------------------------------------------
import android.graphics.BitmapFactory;import android.graphics.Color;import android.os.Bundle;import android.view.View;import android.widget.ImageButton;import android.widget.RelativeLayout;import com.amap.api.maps.AMap;import com.amap.api.maps.CameraUpdate;import com.amap.api.maps.CameraUpdateFactory;import com.amap.api.maps.UiSettings;import com.amap.api.maps.model.BitmapDescriptorFactory;import com.amap.api.maps.model.CameraPosition;import com.amap.api.maps.model.LatLng;import com.amap.api.maps.model.Marker;import com.amap.api.maps.model.MarkerOptions;import com.amap.api.navi.AMapNavi;import com.amap.api.navi.AMapNaviException;import com.amap.api.navi.AMapNaviListener;import com.amap.api.navi.AMapNaviView;import com.amap.api.navi.AMapNaviViewOptions;import com.amap.api.navi.model.AMapNaviTrafficFacilityInfo;import com.amap.api.navi.model.NaviLatLng;import com.amap.api.navi.view.RouteOverLay;import com.amap.api.navi.view.ZoomButtonView;import java.util.ArrayList;import java.util.List;public class CustomRouteActivity extends BaseActivity implements AMapNaviListener { private ArrayList<NaviLatLng> mWayPointList; protected final List<NaviLatLng> sList = new ArrayList<NaviLatLng>(); protected final List<NaviLatLng> eList = new ArrayList<NaviLatLng>(); private double latitudeStart, longitudeStart, marketLatitude, marketLongitude, latitudeEnd, longitudeEnd; private NaviLatLng wayPoint; private ImageButton ibBack; private ZoomButtonView mZoomButtonView; private AMap aMap; private ImageButton ibRefresh; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle bundle = getIntent().getExtras();
//经纬度 if (null != bundle) { latitudeStart = bundle.getDouble("latitude"); longitudeStart = bundle.getDouble("longitude"); marketLatitude = bundle.getDouble("marketLatitude"); marketLongitude = bundle.getDouble("marketLongitude"); latitudeEnd = bundle.getDouble("latitudeEnd"); longitudeEnd = bundle.getDouble("longitudeEnd"); } NaviLatLng mStartLatLng = new NaviLatLng(latitudeStart, longitudeStart); NaviLatLng mEndLatLng = new NaviLatLng(latitudeEnd, longitudeEnd); wayPoint = new NaviLatLng(marketLatitude, marketLongitude); sList.add(mStartLatLng); eList.add(mEndLatLng); mWayPointList = new ArrayList<NaviLatLng>(); setContentView(R.layout.activity_basic_navi); mAMapNaviView = (AMapNaviView) findViewById(R.id.navi_view); mAMapNaviView.onCreate(savedInstanceState); mAMapNaviView.setAMapNaviViewListener(this); ibBack = (ImageButton) findViewById(R.id.ib_back); //自定义缩放控件 mZoomButtonView = (ZoomButtonView) findViewById(R.id.myZoomButtonView); aMap = mAMapNaviView.getMap(); mAMapNaviView.setLazyZoomButtonView(mZoomButtonView); //移动到当前位置 UiSettings mUiSettings = aMap.getUiSettings(); mUiSettings.setZoomControlsEnabled(false); //指南针是否显示 mUiSettings.setCompassEnabled(false); //15是缩放比例,0是倾斜度,30显示比例 CameraUpdate mUpdata = CameraUpdateFactory.newCameraPosition( new CameraPosition(new LatLng(latitudeStart, longitudeStart), 14, 0, 30));//这是地理位置,就是经纬度。 aMap.moveCamera(mUpdata);//定位的方法 //绘制蓝点
drawMarkers(); AMapNaviViewOptions options = mAMapNaviView.getViewOptions(); options.setLayoutVisible(false); //主动隐藏导航光柱 options.setTrafficBarEnabled(false); //关闭自动绘制路线(如果你想自行绘制路线的话,必须关闭!!!) options.setAutoDrawRoute(false); //关闭自动绘制路线(如果你想自行绘制路线的话,必须关闭!!!) options.setAutoDrawRoute(false); mAMapNaviView.setViewOptions(options); mWayPointList.add(wayPoint); } public void drawMarkers() { Marker marker = aMap.addMarker(new MarkerOptions() .position(new LatLng(latitudeStart,longitudeStart)) .title("我的位置") .icon(BitmapDescriptorFactory .defaultMarker(BitmapDescriptorFactory.HUE_AZURE)) .draggable(true));// marker.showInfoWindow();// 设置默认显示一个infowinfow } @Override public void onInitNaviSuccess() { super.onInitNaviSuccess(); /** * 方法: int strategy=mAMapNavi.strategyConvert(congestion, avoidhightspeed, cost, hightspeed, multiplerout * @congestion 躲避拥堵 * @avoidhightspeed 不走高速 * @cost 避免收费 * @hightspeed 高速优先 * @multipleroute 多路 * 说明: 以上参数都是boolean类型,其中multipleroute参数表示是否多条路线,如果为true则此策略会算出多条路线。 * 注意: 不走高速与高速优先不能同时为true 高速优先与避免收费不能同时为true */ int strategy = 0; try { //再次强调,最后一个参数为true时代表多路径,否则代表单路径 strategy = mAMapNavi.strategyConvert(true, false, false, false, false); } catch (Exception e) { e.printStackTrace(); } mAMapNavi.calculateDriveRoute(sList, eList, mWayPointList, strategy); } @Override protected void onResume() { super.onResume(); } @Override public void onCalculateRouteSuccess(int[] ids) {// 如果根据获取的导航路线来自定义绘制 RouteOverLay routeOverlay = new RouteOverLay(mAMapNaviView.getMap(), mAMapNavi.getNaviPath(), this); routeOverlay.setStartPointBitmap(BitmapFactory.decodeResource(this.getResources(), R.drawable.map_user_ic)); routeOverlay.setEndPointBitmap(BitmapFactory.decodeResource(this.getResources(), R.drawable.map_business_ic)); routeOverlay.setWayPointBitmap(BitmapFactory.decodeResource(this.getResources(), R.drawable.map_dispatching_ic)); routeOverlay.setTrafficLine(false); try { routeOverlay.setWidth(30); } catch (AMapNaviException e) { //宽度须>0 e.printStackTrace(); } int color[] = new int[10]; color[0] = getResources().getColor(R.color.color_FF4E80); color[1] = getResources().getColor(R.color.color_FF4E80); color[2] = Color.BLUE; color[3] = Color.YELLOW; color[4] = Color.GRAY; routeOverlay.addToMap(color, mAMapNavi.getNaviPath().getWayPointIndex()); mAMapNavi.startNavi(AMapNavi.GPSNaviMode); } @Override public void OnUpdateTrafficFacility(AMapNaviTrafficFacilityInfo[] aMapNaviTrafficFacilityInfos) { }}
阅读全文
0 0
- Android 高德地图驾车路线规划
- android 高德地图 驾车路线规划
- 高德地图中实现实时定位、驾车路线规划,点间距
- 高德地图WebAPI : 驾车路径规划
- 高德地图JavascriptAPI:驾车路径规划
- Android 高德地图 步行 路线规划
- Android App跳转至百度,高德App的驾车(路线)规划
- 高德地图路线规划
- 【高德地图API】从零开始学高德JS API(五)路线规划——驾车|公交|步行
- 【高德地图API】从零开始学高德JS API(五)路线规划——驾车|公交|步行
- 高德地图驾车路径规划详情获取
- 高德地图Android自定义路线规划的简单实现
- android---高德地图(4)路线规划
- 高德地图——路线规划
- iOS高德地图sdk规划路线
- js-高德地图规划路线
- 高德地图 步行路线规划 Walking
- 高德地图之路线规划
- 软件工程(c编码实践篇) 学习总结
- Lifelong!
- 爬虫安装scrapy
- HDU 1863 畅通工程
- 软件工程(C编码实践篇)学习总结
- android 高德地图 驾车路线规划
- nginx反向代理到tomcat,并在request中获取客户端请求ip
- C++11 条款1:理解模板类型推导
- jsp指令元素,jsp动作元素
- Shiro 总结一
- eclipse 中outline里各个图形代表的含义
- [Unity]使用C#动态创建控件
- mysql如何删除或者添加一行数据
- matlab安装libsvm