高德地图

高德地图:

配置: 1, 导入jar包  build-(1个)文件夹

 

          2, 在build.gilde里添加  sourceSets{

                                                                                    main{

                                                                                             jniLibs.srcDirs= ['libs']

                                                                                    }

                                                                  }

 

         3,清单文件添加  <meta-data android:name="com.amap.api.v2.apikey"   

                                        android:value="key">//开发者申请的key  

                                               </meta-data>

 

         4,xml布局  MapView

 

<com.amap.api.maps.MapView

    android:layout_marginTop="60dp"

   android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:id="@+id/map">

</com.amap.api.maps.MapView>

 

         5,生命周期

 

map.onCreate(savedInstanceState);

 

                            @Override

                protected voidonDestroy() {

          super.onDestroy();

        map.onDestroy();

                  }

 

    @Override

    protected void onResume() {

        super.onResume();

        map.onResume();

    }

 

    @Override

    protected void onPause() {

        super.onPause();

        map.onPause();

    }

 

    @Override

    public voidonSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) {

        super.onSaveInstanceState(outState,outPersistentState);

        map.onSaveInstanceState(outState);

    }

 

   :蓝点显示器:

                   1, if(null==map1){

           map1 = this.map.getMap();

}

 

2,

private void initSlefPosition(){

        myLocationStyle = newMyLocationStyle();

        //设置2秒定位一次

       myLocationStyle.interval(2000);

       myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE);//连续定位、且将视角移动到地图中心点,定位点依照设备方向旋转,并且会跟随设备移动。(1秒1次定位)默认执行此种模式。

       map1.setMyLocationStyle(myLocationStyle);

       // 设置为true表示启动显示定位蓝点,false表示隐藏定位蓝点并不进行定位,默认是false。

       map1.setMyLocationEnabled(true);

       //设置是否显示定位小蓝点,用于满足只想使用定位,不想使用定位小蓝点的场景,

        // 设置false以后图面上不再有定位蓝点的概念,但是会持续回调位置信息。

       myLocationStyle.showMyLocation(true);

    }

 

: POI检索

 

// TODO validate success, do something

       PoiSearch.Query query = newPoiSearch.Query(mPoiString,"",mCityString);

       query.setPageNum(1);//页数

       query.setPageSize(50);//条数

       PoiSearch search = new PoiSearch(MainActivity.this,query);

       search.setOnPoiSearchListener(new PoiSearch.OnPoiSearchListener() {

           @Override

           public void onPoiSearched(PoiResult poiResult, int i) {

                ArrayList<PoiItem> pois =poiResult.getPois();

                for (int j = 0; j<pois.size() ; j++) {

                    PoiItem poiItem =pois.get(j);

                    LatLng latLng = newLatLng(poiItem.getLatLonPoint().getLatitude(),poiItem.getLatLonPoint().getLongitude());

map1.addMarker(newMarkerOptions().position(latLng).title(poiItem.getTitle()).snippet(poiItem.getSnippet()));

 

                }

           }

 

           @Override

           public void onPoiItemSearched(PoiItem poiItem, int i) {

 

           }

       });

       search.searchPOIAsyn();

 

 

:路径规划:

         1:

map1.setOnMarkerClickListener(newAMap.OnMarkerClickListener() {

           @Override

           public boolean onMarkerClick(Marker marker) {

                //自身的位置

                Location myLocation =map1.getMyLocation();

                LatLonPoint start = newLatLonPoint(myLocation.getLatitude(),myLocation.getLongitude());

                //目标的位置

                LatLng position = marker.getPosition();

                LatLonPoint end = newLatLonPoint(position.latitude,position.longitude);

                RouteSearch.FromAndTo fat = newRouteSearch.FromAndTo(start,end);

                // fromAndTo包含路径规划的起点和终点,drivingMode表示驾车模式

                // 第三个参数表示途经点(最多支持16个),第四个参数表示避让区域(最多支持32个),第五个参数表示避让道路

                //创建Query对象,设置路径规划的起点和终止点

         RouteSearch.DriveRouteQuery query =new RouteSearch.DriveRouteQuery(fat, 0, null, null, "");

                //创建RouteSearch对象

               RouteSearch routeSearch= new RouteSearch(MainActivity.this);

                //设置监听

               routeSearch.setRouteSearchListener(MainActivity.this);

                //发起路径规划的算路

               routeSearch.calculateDriveRouteAsyn(query);

                return false;

           }

       });

 

2:监听

 

               实现RouteSearch.OnRouteSearchListener

 

 

@Override

    public voidonBusRouteSearched(BusRouteResult busRouteResult, int i) {

 

    }

 

    @Override

    public void onDriveRouteSearched(DriveRouteResultresult, int errorCode) {

        map1.clear();// 清理地图上的所有覆盖物

        if (errorCode ==AMapException.CODE_AMAP_SUCCESS) {

            if (result != null &&result.getPaths() != null) {

                if (result.getPaths().size()> 0) {

                    final DrivePath drivePath =result.getPaths()

                            .get(0);

                    DrivingRouteOverlaydrivingRouteOverlay = new DrivingRouteOverlay(

                            MainActivity.this,map1, drivePath,

                            result.getStartPos(),

                           result.getTargetPos(), null);

                   drivingRouteOverlay.setNodeIconVisibility(false);//设置节点marker是否显示

                   drivingRouteOverlay.setIsColorfulline(true);//是否用颜色展示交通拥堵情况,默认true

                   drivingRouteOverlay.removeFromMap();

                   drivingRouteOverlay.addToMap();

                   drivingRouteOverlay.zoomToSpan();

                }

            }

        }

    }

 

    @Override

    public voidonWalkRouteSearched(WalkRouteResult walkRouteResult, int i) {

 

    }

 

    @Override

    public voidonRideRouteSearched(RideRouteResult rideRouteResult, int i) {

 

    }

 

//1.复制    com/util/

第一二和倒数第一个类(AMapUtil.java, ChString.java,ToastUtil.java)

         2.复制res1-7( dir1,png-16

         3.复制com下同级overlay文件

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值