300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > 高德地图定位 搜索 导航功能

高德地图定位 搜索 导航功能

时间:2022-05-29 09:59:12

相关推荐

高德地图定位 搜索 导航功能

这个demo其实是我为了熟悉高德地图写出来的,写的时候是我第一次接触高德,所以有写的不好的地方求不喷。

整个实现的过程大致如下:

1:SDK集成

2:界面绘制

3:实现当前定位

4:实现位置搜索

5:根据起点与终点的经纬度进行导航

SDK下载

<RelativeLayout xmlns:android="/apk/res/android"xmlns:app="/apk/res-auto"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><com.amap.api.maps.MapViewandroid:id="@+id/map"android:layout_width="match_parent"android:layout_height="match_parent" /><com.mancj.materialsearchbar.MaterialSearchBarandroid: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" /><ListViewandroid: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>

//在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}

private 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

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。