emmmm,高德好用

先上些图
搜索出来周围的地址,点击之后,利用正地理编码搜索获取经纬度

效果图
![这里写图片描述](https://img-blog.csdn.net/20180706101052576?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzMzODAyNDMx/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70)初始化地图的工具类object InitAmap {fun initAmap(aMap: AMap, locationSource: (LocationSource.OnLocationChangedListener?) -> Unit,marker: (Marker) -> Boolean) {aMap.uiSettings.isZoomControlsEnabled = false// 设置地图默认的指南针是否显示aMap.uiSettings.isCompassEnabled = false// 设置定位监听aMap.setLocationSource(object : LocationSource {override fun deactivate() {}override fun activate(p0: LocationSource.OnLocationChangedListener?) {locationSource(p0)}})// 设置默认定位按钮是否显示aMap.uiSettings.isMyLocationButtonEnabled = false// 设置为true表示显示定位层并可触发定位,false表示隐藏定位层并不可触发定位,默认是falseaMap.isMyLocationEnabled = true
//        aMap.setMyLocationType(AMap.LOCATION_TYPE_LOCATE)aMap.setOnMarkerClickListener {marker(it)}}
}

然后布局代码 activity_map_search

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"><com.amap.api.maps.MapView
        android:id="@+id/map_ams"android:layout_width="match_parent"android:layout_height="match_parent"></com.amap.api.maps.MapView><android.support.v7.widget.RecyclerView
        android:id="@+id/rlv_search_ams"android:background="@color/colorWhite"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_gravity="bottom"android:paddingBottom="12dp"></android.support.v7.widget.RecyclerView><!-- android:imeOptions="actionSearch" 把回车键改为搜索--><EditText
        android:id="@+id/et_search_ams"android:layout_width="match_parent"android:imeOptions="actionSearch"android:inputType="text"android:maxLines="1"android:layout_height="wrap_content"android:layout_margin="12dp"android:padding="8dp"android:hint="输入详细地址查询"android:background="@drawable/shape_fill_white_with_gray_rec_bg"/>
</FrameLayout>

activity中的使用
这里面用到的定位初始化是我昨天写的个工具类高德地图定位工具类

class MapSearchActivity : BaseActivity() {//地图private lateinit var aMap: AMap//在地图上添加的一个一直在屏幕中心的点private var locationMaker: Marker? = nullprivate var mListener: LocationSource.OnLocationChangedListener? = nulloverride fun bindLayout() = R.layout.activity_map_searchoverride fun beforeSetContentView() {super.beforeSetContentView()window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)}override fun init(savedInstanceState: Bundle?) {//初始化地图map_ams.onCreate(savedInstanceState)aMap = map_ams.mapinitAmap(aMap, { locationSourceListener(it) }, { markerListener(it) })//设置地图拖动监听aMap.setOnCameraChangeListener(object : AMap.OnCameraChangeListener {override fun onCameraChangeFinish(cameraPosition: CameraPosition) {val latLng = cameraPosition.targetsearchNearby(latLng)}override fun onCameraChange(p0: CameraPosition?) {}})//定位初始化LocationInfo.getLocationInfo(this, {locationSuccess(it)})//搜索框监听et_search_ams.setOnKeyListener { v, keyCode, event ->if (keyCode == KeyEvent.KEYCODE_ENTER) {val string = et_search_ams.text.toString()getLatLngByAddress(this, string, string, { getLatlngSuccess(it) })val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager// 强制隐藏软键盘imm.hideSoftInputFromWindow(et_search_ams.windowToken, 0)}false}}private fun locationSourceListener(locationSource: LocationSource.OnLocationChangedListener?) {mListener = locationSource}//marker的点击事件监听private fun markerListener(marker: Marker): Boolean {return true}private fun locationSuccess(location: AMapLocation) {//显示系统小蓝点mListener?.let { mListener!!.onLocationChanged(location) }// 设置缩放级别aMap.animateCamera(CameraUpdateFactory.newLatLngZoom(LatLng(location.latitude, location.longitude), 17f))// 将地图移动到定位点aMap.moveCamera(CameraUpdateFactory.changeLatLng(LatLng(location.latitude, location.longitude)))val markerOption = MarkerOptions()markerOption.icon(BitmapDescriptorFactory.fromResource(R.drawable.icon_location)).position(LatLng(location.latitude, location.longitude)).draggable(true).title("").snippet("哼哼哈哈哈")locationMaker = aMap.addMarker(markerOption)locationMaker?.setPositionByPixels(map_ams.width / 2,map_ams.height / 2)searchNearby(LatLng(location.latitude, location.longitude))}/*** 开始搜索附近*/private fun searchNearby(latLng: LatLng) {val query = PoiSearch.Query("", "", "")query.pageSize = 6val search = PoiSearch(this, query)search.bound = PoiSearch.SearchBound(LatLonPoint(latLng.latitude, latLng.longitude), 10000)search.setOnPoiSearchListener(object : PoiSearch.OnPoiSearchListener {override fun onPoiItemSearched(p0: PoiItem?, p1: Int) {}override fun onPoiSearched(result: PoiResult?, code: Int) {if (code == 1000) {val query = result?.queryval pois = result?.poisrlv_search_ams.layoutManager = LinearLayoutManager(this@MapSearchActivity)rlv_search_ams.adapter = object : CommonAdapter<PoiItem>(this@MapSearchActivity, R.layout.item_rlv_search_ams, pois) {override fun convert(holder: ViewHolder, t: Any?, position: Int) {val data = t as PoiItemholder.setText(R.id.tv_title_irsa, data.title)holder.setText(R.id.tv_address_irsa, data.snippet)holder.convertView.setOnClickListener {val address = data.provinceName + data.cityName + data.adName + data.snippetLog.e("aa", "点击的地址:$address")getLatLngByAddress(this@MapSearchActivity, data.cityCode, address, { getLatlngSuccess(it) })}}}} else {TOT("搜索错误")}}})search.searchPOIAsyn()}private fun getLatlngSuccess(geocodeResult: GeocodeResult) {val address = geocodeResult.geocodeAddressList[0]Log.e("aa", ("经纬度值:" + address.latLonPoint + "\n位置描述:"+ address.formatAddress))val latLng = LatLng(address.latLonPoint.latitude, address.latLonPoint.longitude)searchNearby(latLng)aMap.moveCamera(CameraUpdateFactory.changeLatLng(latLng))//设置返回值}override fun onResume() {super.onResume()// 重新绘制加载地图map_ams.onResume()}override fun onPause() {super.onPause()// 暂停地图的绘制map_ams.onPause()}override fun onDestroy() {super.onDestroy()// 销毁地图map_ams.onDestroy()}
}

根据地址获取经纬度–高德地图 方法

fun getLatLngByAddress(context: Context,city:String,address:String,success:(GeocodeResult)->Unit){//构造 GeocodeSearch 对象,并设置监听。val geocodeSearch = GeocodeSearch(context)geocodeSearch.setOnGeocodeSearchListener(object :GeocodeSearch.OnGeocodeSearchListener{override fun onRegeocodeSearched(p0: RegeocodeResult?, position: Int) {}override fun onGeocodeSearched(geocodeResult: GeocodeResult?, position: Int) {if (position == AMapException.CODE_AMAP_SUCCESS) {if (geocodeResult?.geocodeAddressList != null&& geocodeResult.geocodeAddressList.size > 0) {success(geocodeResult)}}}})
//通过GeocodeQuery设置查询参数,调用getFromLocationNameAsyn(GeocodeQuery geocodeQuery) 方法发起请求。
//address表示地址,第二个参数表示查询城市,中文或者中文全拼,citycode、adcode都okval query =GeocodeQuery(address, city)geocodeSearch.getFromLocationNameAsyn(query)
}

哦,中心点的图标

希望能帮助到有需要的人

高德地图 搜索定位以及自由滑动地图展示周边位置信息相关推荐

  1. 高德地图怎么搜索marker_2018-07-06 高德地图搜索定位,滑动地图显示周边信息,根据地址搜经...

    emmmm,效果图先行(搜索定位以及自由滑动地图展示周边位置信息,根据点击的位置获取经纬度) aa.gif 主要代码package com.dydd.wsp.dreamtree.ui.mapimpor ...

  2. 通过腾讯地图、高德地图、百度地图开发接口获取坐标对应的周边相关信息

    通过腾讯地图.高德地图.百度地图开发接口获取坐标对应的周边相关信息 更新: 以前出于好意暴露了个人的KEY,现已被烂用.为不影响您的业务,请使用我的KEY的朋友去申请自己的KEY,我的KEY将在不久后 ...

  3. android-注释超详细-高德地图实现定位和切换地图类型

    具体实现效果 1.普通模式 2.夜晚模式 3.显示交通 在夜间模式下的交通 4.卫星模式 1.实现基本地图显示 具体可参考上一篇博客安卓开发显示高德地图 2.修改AndroidManifest.xml ...

  4. 安卓百度地图之定位图标在地图上显示

    此文章接上一篇文件:安卓百度地图之定位_zpon_wangxuan的博客-CSDN博客,对于地图上显示定位图标就是在地图上添加一个地图的marker就可以了: 布局文件代码: <LinearLa ...

  5. 高德地图 搜索定位 搜索关键词 定位

    效果图: 关键代码 AMap.service(["AMap.PlaceSearch","'AMap.AutoComplete'"], function() {v ...

  6. 高德地图搜索,点击地图获取经纬度

    1.H5页面 一个搜索框.一个经纬度接收框 <input class="layui-input" placeholder="地名" name=" ...

  7. Android 天气APP(二十八)地图搜索定位

    还是比较简单的,然后进入到MapWeatherActivity ImageView ivSearch;//搜索图标 @BindView(R.id.ed_search) EditText edSearc ...

  8. js百度地图android定位不准,百度地图js定位不准

    浏览器H5定位即navigator.geolocation,通过IP或者域名的形式,如:http://172.21.3.82:8080 和http://b.cunzhang.com进行访问时,调用na ...

  9. android百度地图定位跳转中心点,百度地图,拖动地图,定位marker固定在屏幕中心位置...

    以下为百度地图相关效果图: 注:该例子主要思路是将覆盖物(marker)通过css定位上去的,但是存在一个问题,当浏览器窗口宽度改变时,覆盖物会自动定位到地图中心位置,但是地图可能不会. map ht ...

最新文章

  1. Android Jetpack 组件之 Lifecycle使用
  2. idea中配置maven的骨架本地下载方式
  3. 2022QS世界大学排名:清北跻身世界前20
  4. 深度神经网络:WX+B vs XW+B,作者原文已经删除,转载过来了~~~
  5. 【Java】第一阶段练习题
  6. JavaScript高级程序设计之EventUtil
  7. Vhost dataplane in Qemu | PDF
  8. 边缘计算工作负载:虚拟机,容器还是裸机?
  9. 10分钟电子邮箱,临时邮箱
  10. 域客户统一关闭UAC
  11. 程序员的自我修养 -- 读书笔记
  12. redspider无法启动,并行配置不正确
  13. 40几岁读研究生计算机,年近四十岁,还有必要去考研和继续考博吗?不建议考全日制研究生...
  14. 桌面显卡天梯图和桌面cpu天梯图
  15. 嵌入式linux/鸿蒙开发板(IMX6ULL)开发流程(六)烧写整个系统或更新部分系统
  16. [推荐]零售业CRM应用突破之道 穆穆-movno1 (入选推荐日志,加10币)
  17. 【工具】JAVA 全角转半角 半角转全角
  18. Python:生成随机偏态分布
  19. 安装 Windows Server 2019 VM虚拟机
  20. linux系centos的软件,centos系统安装下载

热门文章

  1. import和export
  2. sift论文_从十篇热门学术论文看计算机视觉的未来
  3. Axon Framework简介
  4. Glassfish Request URI is too large 问题的解决
  5. PS改变图像尺寸和分辨率保存为tif图片颜色变成黑色-解决办法
  6. CPU个数、CPU物理核数、CPU逻辑核数、vCPU数之间的区别
  7. 判断是否为平衡二叉树(Java)
  8. 市场因子(Market Factor)——投资组合分析(EAP.portfolio_analysis)
  9. 基于jQuery的TreeGrid组件
  10. c语言顺序线性表的实现