Commit 2253f122 authored by shiyl's avatar shiyl

修复高德地图so库异常问题,并动态配置amap_key

parent e40cef0d
...@@ -39,6 +39,7 @@ android { ...@@ -39,6 +39,7 @@ android {
manifestPlaceholders = [ manifestPlaceholders = [
app_name : "商家版测试", app_name : "商家版测试",
file_provider: rootProject.ext.android.applicationId + ".debug.fileprovider", file_provider: rootProject.ext.android.applicationId + ".debug.fileprovider",
amap_key : rootProject.ext.amap.amap_debug_key,
] ]
} }
release { release {
...@@ -48,6 +49,7 @@ android { ...@@ -48,6 +49,7 @@ android {
manifestPlaceholders = [ manifestPlaceholders = [
app_name : "生活圈商家版", app_name : "生活圈商家版",
file_provider: rootProject.ext.android.applicationId + ".fileprovider", file_provider: rootProject.ext.android.applicationId + ".fileprovider",
amap_key : rootProject.ext.amap.amap_release_key,
] ]
} }
} }
...@@ -73,8 +75,8 @@ android { ...@@ -73,8 +75,8 @@ android {
} }
dependencies { dependencies {
// 注意高德地图jar引入需要使用compile,implementation不生效 // 注意高德地图jar引入需要其他组件可以使用,故而api
compile fileTree(include: '*.jar', dir: 'libs') api fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
// kotlin实现MVVM框架之使用DataBinding之unresolved reference: BR解决办法 // kotlin实现MVVM框架之使用DataBinding之unresolved reference: BR解决办法
kapt "com.android.databinding:compiler:4.0.1" kapt "com.android.databinding:compiler:4.0.1"
......
...@@ -16,5 +16,16 @@ ...@@ -16,5 +16,16 @@
<!--允许程序访问CellID或WiFi热点来获取粗略的位置--> <!--允许程序访问CellID或WiFi热点来获取粗略的位置-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<application>
<!--高德地图配置 start -->
<meta-data
android:name="com.amap.api.v2.apikey"
android:value="${amap_key}" />
<service android:name="com.amap.api.location.APSService" />
<!--高德地图配置 end -->
</application>
</manifest> </manifest>
...@@ -3,7 +3,6 @@ package com.yidian.shenghuoquan.newscontent.ui.store ...@@ -3,7 +3,6 @@ package com.yidian.shenghuoquan.newscontent.ui.store
import android.content.Intent import android.content.Intent
import android.location.Location import android.location.Location
import android.os.Bundle import android.os.Bundle
import android.util.Log
import android.view.View import android.view.View
import android.widget.AdapterView import android.widget.AdapterView
import com.amap.api.maps.AMap import com.amap.api.maps.AMap
...@@ -20,24 +19,25 @@ import com.yidian.common.PoiListAdapter ...@@ -20,24 +19,25 @@ import com.yidian.common.PoiListAdapter
import com.yidian.common.base.BaseActivity import com.yidian.common.base.BaseActivity
import com.yidian.shenghuoquan.newscontent.R import com.yidian.shenghuoquan.newscontent.R
import com.yidian.shenghuoquan.newscontent.databinding.ActivitySelectAddressBinding import com.yidian.shenghuoquan.newscontent.databinding.ActivitySelectAddressBinding
import timber.log.Timber
/** /**
* Author: sym * 选择门店地址
* Date: 2021/6/24 2:10 PM
* Describe:
*/ */
class SelectAddressActivity : BaseActivity<ActivitySelectAddressBinding>(), OnMyLocationChangeListener, AMap.OnMapClickListener, OnPoiSearchListener{ class SelectAddressActivity : BaseActivity<ActivitySelectAddressBinding>(), OnMyLocationChangeListener, AMap.OnMapClickListener,
OnPoiSearchListener {
private lateinit var mapView: MapView private lateinit var mapView: MapView
private var adapter = PoiListAdapter() private var adapter = PoiListAdapter()
private var resultIntent = Intent() private var resultIntent = Intent()
private lateinit var data: List<PoiItem> private lateinit var data: List<PoiItem>
private var myLocationStyle: MyLocationStyle? = null private var myLocationStyle: MyLocationStyle? = null
var bitmapDescriptor: BitmapDescriptor? = null private var bitmapDescriptor: BitmapDescriptor? = null
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
var aMap: AMap? = null private var aMap: AMap? = null
override fun createViewBinding(): ActivitySelectAddressBinding { override fun createViewBinding(): ActivitySelectAddressBinding {
return ActivitySelectAddressBinding.inflate(layoutInflater) return ActivitySelectAddressBinding.inflate(layoutInflater)
...@@ -73,8 +73,8 @@ class SelectAddressActivity : BaseActivity<ActivitySelectAddressBinding>(), OnMy ...@@ -73,8 +73,8 @@ 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()
} }
...@@ -109,38 +109,30 @@ class SelectAddressActivity : BaseActivity<ActivitySelectAddressBinding>(), OnMy ...@@ -109,38 +109,30 @@ class SelectAddressActivity : BaseActivity<ActivitySelectAddressBinding>(), OnMy
private fun setUpMap() { private fun setUpMap() {
// 如果要设置定位的默认状态,可以在此处进行设置 // 如果要设置定位的默认状态,可以在此处进行设置
myLocationStyle = MyLocationStyle() myLocationStyle = MyLocationStyle()
aMap!!.myLocationStyle = myLocationStyle aMap?.myLocationStyle = myLocationStyle
aMap!!.isMyLocationEnabled = true // 设置为true表示显示定位层并可触发定位,false表示隐藏定位层并不可触发定位,默认是false aMap?.isMyLocationEnabled = true // 设置为true表示显示定位层并可触发定位,false表示隐藏定位层并不可触发定位,默认是false
aMap!!.setOnMapClickListener(this) // 设置点击marker事件监听器 aMap?.setOnMapClickListener(this) // 设置点击marker事件监听器
} }
//定位 //定位
override fun onMyLocationChange(location: Location?) { override fun onMyLocationChange(location: Location?) {
// 定位回调监听 // 定位回调监听
if (location != null) { if (location != null) {
Log.e("amap", "onMyLocationChange 定位成功, lat: " + location.latitude + " lon: " + location.longitude) Timber.tag("amap").e("onMyLocationChange 定位成功, lat: " + location.latitude + " lon: " + location.longitude)
val bundle: Bundle = location.extras val bundle: Bundle = location.extras
if (bundle != null) { val errorCode = bundle.getInt(MyLocationStyle.ERROR_CODE)
val errorCode = bundle.getInt(MyLocationStyle.ERROR_CODE) val errorInfo = bundle.getString(MyLocationStyle.ERROR_INFO)
val errorInfo = bundle.getString(MyLocationStyle.ERROR_INFO) // 定位类型,可能为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 aMap?.isMyLocationEnabled = false // 设置为true表示显示定位层并可触发定位,false表示隐藏定位层并不可触发定位,默认是false
updataCurrentMarker(LatLng(location.latitude,location.longitude)) updataCurrentMarker(LatLng(location.latitude, location.longitude))
/* Timber.tag("amap").e("定位信息, code: $errorCode errorInfo: $errorInfo locationType: $locationType")
errorCode
errorInfo
locationType
*/Log.e("amap", "定位信息, code: $errorCode errorInfo: $errorInfo locationType: $locationType")
} else {
Log.e("amap", "定位信息, bundle is null ")
}
} else { } else {
Log.e("amap", "定位失败") Timber.tag("amap").e("定位失败")
} }
} }
...@@ -156,15 +148,15 @@ class SelectAddressActivity : BaseActivity<ActivitySelectAddressBinding>(), OnMy ...@@ -156,15 +148,15 @@ class SelectAddressActivity : BaseActivity<ActivitySelectAddressBinding>(), OnMy
markerOption.icon(bitmapDescriptor) markerOption.icon(bitmapDescriptor)
markerOption.anchor(0F, 1F) markerOption.anchor(0F, 1F)
currentMarker?.remove() currentMarker?.remove()
currentMarker = aMap!!.addMarker(markerOption) currentMarker = aMap?.addMarker(markerOption)
currentMarker!!.setObject(latLng) currentMarker?.setObject(latLng)
boundsBuilder?.include(latLng) boundsBuilder?.include(latLng)
queryPoi() queryPoi()
} }
//poi搜索 //poi搜索
private fun queryPoi() { private fun queryPoi() {
val latLng = currentMarker!!.getObject() as LatLng val latLng = currentMarker?.getObject() as LatLng
val typeRange = "汽车服务|汽车销售|" + val typeRange = "汽车服务|汽车销售|" +
"汽车维修|摩托车服务|餐饮服务|购物服务|生活服务|体育休闲服务|医疗保健服务|" + "汽车维修|摩托车服务|餐饮服务|购物服务|生活服务|体育休闲服务|医疗保健服务|" +
"住宿服务|风景名胜|商务住宅|政府机构及社会团体|科教文化服务|交通设施服务|" + "住宿服务|风景名胜|商务住宅|政府机构及社会团体|科教文化服务|交通设施服务|" +
...@@ -174,8 +166,12 @@ class SelectAddressActivity : BaseActivity<ActivitySelectAddressBinding>(), OnMy ...@@ -174,8 +166,12 @@ class SelectAddressActivity : BaseActivity<ActivitySelectAddressBinding>(), OnMy
query.pageSize = 1000 // 设置每页最多返回多少条poiitem,一次加载全部 query.pageSize = 1000 // 设置每页最多返回多少条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(
latLng.longitude), 500) //设置周边搜索的中心点以及区域 LatLonPoint(
latLng.latitude,
latLng.longitude
), 500
) //设置周边搜索的中心点以及区域
poiSearch.setOnPoiSearchListener(this) //设置数据返回的监听器 poiSearch.setOnPoiSearchListener(this) //设置数据返回的监听器
poiSearch.searchPOIAsyn() poiSearch.searchPOIAsyn()
...@@ -186,7 +182,7 @@ class SelectAddressActivity : BaseActivity<ActivitySelectAddressBinding>(), OnMy ...@@ -186,7 +182,7 @@ class SelectAddressActivity : BaseActivity<ActivitySelectAddressBinding>(), OnMy
if (rCode == AMapException.CODE_AMAP_SUCCESS) { if (rCode == AMapException.CODE_AMAP_SUCCESS) {
if (poiResult?.query != null) { if (poiResult?.query != null) {
val poiItems: List<PoiItem> = poiResult.pois // 取得第一页的poiitem数据,页数从数字0开始 val poiItems: List<PoiItem> = poiResult.pois // 取得第一页的poiitem数据,页数从数字0开始
if (poiItems != null && poiItems.isNotEmpty()) { if (poiItems.isNotEmpty()) {
data = poiItems data = poiItems
adapter.setData(poiItems) adapter.setData(poiItems)
} }
......
...@@ -35,7 +35,7 @@ android { ...@@ -35,7 +35,7 @@ android {
} }
buildTypes { buildTypes {
debug { debug {
// applicationIdSuffix ".debug" applicationIdSuffix ".debug"
buildConfigField("String", "API_URL", rootProject.ext.buildParams.debug.API_URL) buildConfigField("String", "API_URL", rootProject.ext.buildParams.debug.API_URL)
buildConfigField("String", "PROVIDER_NAME", '\"' + rootProject.ext.android.applicationId + ".debug.fileprovider" + '\"') buildConfigField("String", "PROVIDER_NAME", '\"' + rootProject.ext.android.applicationId + ".debug.fileprovider" + '\"')
manifestPlaceholders = [ manifestPlaceholders = [
...@@ -101,7 +101,7 @@ android { ...@@ -101,7 +101,7 @@ android {
} }
dependencies { dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"]) implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
// kotlin实现MVVM框架之使用DataBinding之unresolved reference: BR解决办法 // kotlin实现MVVM框架之使用DataBinding之unresolved reference: BR解决办法
kapt "com.android.databinding:compiler:4.0.1" kapt "com.android.databinding:compiler:4.0.1"
......
...@@ -368,3 +368,32 @@ public static final int *; ...@@ -368,3 +368,32 @@ public static final int *;
-keep class com.yalantis.ucrop** { *; } -keep class com.yalantis.ucrop** { *; }
-keep interface com.yalantis.ucrop** { *; } -keep interface com.yalantis.ucrop** { *; }
#高德地图
#3D 地图 V5.0.0之前:
-keep class com.amap.api.maps.**{*;}
-keep class com.autonavi.amap.mapcore.*{*;}
-keep class com.amap.api.trace.**{*;}
#3D 地图 V5.0.0之后:
-keep class com.amap.api.maps.**{*;}
-keep class com.autonavi.**{*;}
-keep class com.amap.api.trace.**{*;}
#定位
-keep class com.amap.api.location.**{*;}
-keep class com.amap.api.fence.**{*;}
-keep class com.loc.**{*;}
-keep class com.autonavi.aps.amapapi.model.**{*;}
#搜索
-keep class com.amap.api.services.**{*;}
#2D地图
-keep class com.amap.api.maps2d.**{*;}
-keep class com.amap.api.mapcore2d.**{*;}
#导航
-keep class com.amap.api.navi.**{*;}
-keep class com.autonavi.**{*;}
...@@ -44,9 +44,7 @@ ...@@ -44,9 +44,7 @@
tools:replace="android:allowBackup,android:label" tools:replace="android:allowBackup,android:label"
tools:targetApi="n"> tools:targetApi="n">
<meta-data
android:name="com.amap.api.v2.apikey"
android:value="0b8dd2229f4568b508e51865e402e04a" />
<!-- 以下为友盟分享基本配置信息 start--> <!-- 以下为友盟分享基本配置信息 start-->
<provider <provider
android:name="androidx.core.content.FileProvider" android:name="androidx.core.content.FileProvider"
...@@ -243,7 +241,6 @@ ...@@ -243,7 +241,6 @@
</intent-filter> </intent-filter>
</service> </service>
<service android:name="com.amap.api.location.APSService" />
<service <service
android:name="com.umeng.message.UmengDownloadResourceService" android:name="com.umeng.message.UmengDownloadResourceService"
......
...@@ -11,13 +11,20 @@ ext { ...@@ -11,13 +11,20 @@ ext {
isApplication : false, isApplication : false,
isAppUpgradeOnline: 'true' // 上线前需要开启版本升级线上环境 true isAppUpgradeOnline: 'true' // 上线前需要开启版本升级线上环境 true
] ]
// 高德地图的key
amap = [
amap_debug_key : '0b8dd2229f4568b508e51865e402e04a',
amap_release_key: '9dc8e3fe44680c65de8dbfd808742b10',
]
buildParams = [ buildParams = [
debug : [ debug : [
API_URL: '"http://bp-dev.go2yd.com"', API_URL : '"http://bp-dev.go2yd.com"',
AMAP_KEY: '"0b8dd2229f4568b508e51865e402e04a"',
], ],
release: [ release: [
API_URL: '"http://bp-test.go2yd.com"', API_URL : '"http://bp-test.go2yd.com"',
// API_URL: '"https://bp.go2yd.com"', // API_URL: '"https://bp.go2yd.com"',
AMAP_KEY: '"9dc8e3fe44680c65de8dbfd808742b10"',
] ]
] ]
} }
......
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