Commit 02a0e876 authored by 宋永孟's avatar 宋永孟

add 添加初始定位

parent 65f2b6b3
...@@ -5,6 +5,9 @@ import android.os.Bundle ...@@ -5,6 +5,9 @@ import android.os.Bundle
import android.util.Log import android.util.Log
import android.view.View import android.view.View
import android.widget.Toast import android.widget.Toast
import com.amap.api.location.AMapLocation
import com.amap.api.location.AMapLocationClient
import com.amap.api.location.AMapLocationListener
import com.amap.api.maps.AMap import com.amap.api.maps.AMap
import com.amap.api.maps.AMap.OnMyLocationChangeListener import com.amap.api.maps.AMap.OnMyLocationChangeListener
import com.amap.api.maps.MapView import com.amap.api.maps.MapView
...@@ -28,7 +31,7 @@ import kotlinx.android.synthetic.main.activity_select_address.* ...@@ -28,7 +31,7 @@ import kotlinx.android.synthetic.main.activity_select_address.*
* Date: 2021/6/24 2:10 PM * Date: 2021/6/24 2:10 PM
* Describe: * Describe:
*/ */
class SelectAddressActivity : BaseActivity<ActivitySelectAddressBinding>(), OnMyLocationChangeListener, AMap.OnMapClickListener, OnPoiSearchListener { class SelectAddressActivity : BaseActivity<ActivitySelectAddressBinding>(), OnMyLocationChangeListener, AMap.OnMapClickListener, OnPoiSearchListener, AMapLocationListener {
private lateinit var mapView: MapView private lateinit var mapView: MapView
private var adapter = PoiListAdapter() private var adapter = PoiListAdapter()
private var myLocationStyle: MyLocationStyle? = null private var myLocationStyle: MyLocationStyle? = null
...@@ -36,6 +39,7 @@ class SelectAddressActivity : BaseActivity<ActivitySelectAddressBinding>(), OnMy ...@@ -36,6 +39,7 @@ class SelectAddressActivity : BaseActivity<ActivitySelectAddressBinding>(), OnMy
private var markerView: View? = null private var markerView: View? = null
private var currentMarker: Marker? = null private var currentMarker: Marker? = null
private var boundsBuilder: LatLngBounds.Builder? = null private var boundsBuilder: LatLngBounds.Builder? = null
private var mlocationClient = AMapLocationClient(this)
var aMap: AMap? = null var aMap: AMap? = null
...@@ -52,8 +56,9 @@ class SelectAddressActivity : BaseActivity<ActivitySelectAddressBinding>(), OnMy ...@@ -52,8 +56,9 @@ class SelectAddressActivity : BaseActivity<ActivitySelectAddressBinding>(), OnMy
mapView = viewBind.map mapView = viewBind.map
viewBind.poiList.adapter = adapter viewBind.poiList.adapter = adapter
mapView.onCreate(savedInstanceState) mapView.onCreate(savedInstanceState)
bitmapDescriptor = BitmapDescriptorFactory.fromView(markerView)
markerView = layoutInflater.inflate(R.layout.layout_service_addr_map_marker, null) markerView = layoutInflater.inflate(R.layout.layout_service_addr_map_marker, null)
bitmapDescriptor = BitmapDescriptorFactory.fromView(markerView)
boundsBuilder = LatLngBounds.Builder() boundsBuilder = LatLngBounds.Builder()
if (aMap == null) { if (aMap == null) {
...@@ -63,10 +68,7 @@ class SelectAddressActivity : BaseActivity<ActivitySelectAddressBinding>(), OnMy ...@@ -63,10 +68,7 @@ class SelectAddressActivity : BaseActivity<ActivitySelectAddressBinding>(), OnMy
//设置SDK 自带定位消息监听 //设置SDK 自带定位消息监听
aMap!!.setOnMyLocationChangeListener(this) aMap!!.setOnMyLocationChangeListener(this)
aMap!!.myLocationStyle = myLocationStyle!!.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATE) aMap!!.myLocationStyle = myLocationStyle!!.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATE)
viewBind.selectAddBackBtn.setOnClickListener { viewBind.selectAddBackBtn.setOnClickListener {
finish() finish()
} }
...@@ -102,9 +104,13 @@ class SelectAddressActivity : BaseActivity<ActivitySelectAddressBinding>(), OnMy ...@@ -102,9 +104,13 @@ class SelectAddressActivity : BaseActivity<ActivitySelectAddressBinding>(), OnMy
// 如果要设置定位的默认状态,可以在此处进行设置 // 如果要设置定位的默认状态,可以在此处进行设置
myLocationStyle = MyLocationStyle() myLocationStyle = MyLocationStyle()
aMap!!.myLocationStyle = myLocationStyle aMap!!.myLocationStyle = myLocationStyle
aMap!!.uiSettings.isMyLocationButtonEnabled = false // 设置默认定位按钮是否显示
aMap!!.isMyLocationEnabled = true // 设置为true表示显示定位层并可触发定位,false表示隐藏定位层并不可触发定位,默认是false aMap!!.isMyLocationEnabled = true // 设置为true表示显示定位层并可触发定位,false表示隐藏定位层并不可触发定位,默认是false
aMap!!.setOnMapClickListener(this) // 设置点击marker事件监听器 aMap!!.setOnMapClickListener(this) // 设置点击marker事件监听器
//设置定位监听
mlocationClient.setLocationListener(this)
mlocationClient.startLocation()
} }
//定位 //定位
...@@ -119,6 +125,11 @@ class SelectAddressActivity : BaseActivity<ActivitySelectAddressBinding>(), OnMy ...@@ -119,6 +125,11 @@ class SelectAddressActivity : BaseActivity<ActivitySelectAddressBinding>(), OnMy
// 定位类型,可能为GPS WIFI等,具体可以参考官网的定位SDK介绍 // 定位类型,可能为GPS WIFI等,具体可以参考官网的定位SDK介绍
val locationType = bundle.getInt(MyLocationStyle.LOCATION_TYPE) val locationType = bundle.getInt(MyLocationStyle.LOCATION_TYPE)
aMap!!.isMyLocationEnabled = false // 设置为true表示显示定位层并可触发定位,false表示隐藏定位层并不可触发定位,默认是false
updataCurrentMarker(LatLng(location.latitude,location.longitude))
/* /*
errorCode errorCode
errorInfo errorInfo
...@@ -166,7 +177,6 @@ class SelectAddressActivity : BaseActivity<ActivitySelectAddressBinding>(), OnMy ...@@ -166,7 +177,6 @@ class SelectAddressActivity : BaseActivity<ActivitySelectAddressBinding>(), OnMy
//cityCode表示POI搜索区域,(这里可以传空字符串,空字符串代表全国在全国范围内进行搜索) //cityCode表示POI搜索区域,(这里可以传空字符串,空字符串代表全国在全国范围内进行搜索)
val query: PoiSearch.Query = PoiSearch.Query("", typeRange, "") val query: PoiSearch.Query = PoiSearch.Query("", typeRange, "")
query.pageSize = 10 // 设置每页最多返回多少条poiitem query.pageSize = 10 // 设置每页最多返回多少条poiitem
query.pageNum = 1 //设置查第一页 query.pageNum = 1 //设置查第一页
val poiSearch = PoiSearch(this, query) val poiSearch = PoiSearch(this, query)
poiSearch.bound = PoiSearch.SearchBound(LatLonPoint(latLng.latitude, poiSearch.bound = PoiSearch.SearchBound(LatLonPoint(latLng.latitude,
...@@ -196,4 +206,9 @@ class SelectAddressActivity : BaseActivity<ActivitySelectAddressBinding>(), OnMy ...@@ -196,4 +206,9 @@ class SelectAddressActivity : BaseActivity<ActivitySelectAddressBinding>(), OnMy
override fun onPoiItemSearched(p0: PoiItem?, p1: Int) { override fun onPoiItemSearched(p0: PoiItem?, p1: Int) {
} }
override fun onLocationChanged(p0: AMapLocation?) {
Log.d("song_test","有数据过来")
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment