这个demo其实是我为了熟悉高德地图写出来的,写的时候是我第一次接触高德,所以有写的不好的地方求不喷。
整个实现的过程大致如下:
1:SDK集成
2:界面绘制
3:实现当前定位
4:实现位置搜索
5:根据起点与终点的经纬度进行导航
SDK下载
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <com.amap.api.maps.MapView android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" /> <com.mancj.materialsearchbar.MaterialSearchBar android:id="@+id/searchBar" style="@style/MaterialSearchBarLight" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:layout_marginTop="10dp" app:mt_hint="输入目的地" app:mt_speechMode="true" /> <ListView android:id="@+id/list" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/searchBar" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:layout_marginTop="5dp" android:background="#ffffff" /> </RelativeLayout>
复制代码
1
2
3
4
5
6
7
8
9
10
11
12//在activity执行onCreate时执行mMapView.onCreate(savedInstanceState),创建地图 mMapView.onCreate(savedInstanceState); //初始化地图控制器对象 if (aMap == null) { aMap = mMapView.getMap(); UiSettings settings = aMap.getUiSettings(); aMap.setLocationSource(this);//设置了定位的监听 // 是否显示定位按钮 settings.setMyLocationButtonEnabled(true); aMap.setMyLocationEnabled(true);//显示定位层并且可以触发定位,默认是flase }
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27private void location() { //初始化定位 mLocationClient = new AMapLocationClient(getApplicationContext()); //设置定位回调监听 mLocationClient.setLocationListener(this); //初始化定位参数 mLocationOption = new AMapLocationClientOption(); //设置定位模式为Hight_Accuracy高精度模式,Battery_Saving为低功耗模式,Device_Sensors是仅设备模式 mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy); //设置是否强制刷新WIFI,默认为强制刷新 mLocationOption.setWifiActiveScan(true); //设置定位间隔 默认采用连续定位模式,时间间隔为2000ms 可以自定义 mLocationOption.setInterval(2000); //设置是否返回地址信息,默认返回 mLocationOption.setNeedAddress(true); //设置是否允许模拟软件Mock位置结果,多为模拟GPS定位结果,默认为true,允许模拟位置 mLocationOption.setMockEnable(true); //设置定位请求超时时间,默认为30秒 mLocationOption.setHttpTimeOut(20000); //设置是否开启定位缓存机制 默认开启 mLocationOption.setLocationCacheEnable(false); //给定位客户端对象设置定位参数 mLocationClient.setLocationOption(mLocationOption); //启动定位 mLocationClient.startLocation(); }
以上是部分关于定位的代码
我这边是将定位搜索导航都整合了一下
源码可以去git上下载,我这边就不多说了
代码传送门
喜欢请star,不喜欢也请star
最后
以上就是留胡子蛋挞最近收集整理的关于高德地图定位,搜索,导航功能的全部内容,更多相关高德地图定位内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复