Commit 9b97659d authored by fengruiyu's avatar fengruiyu

修改百度SDK地图动画

修改百度SDK地图国内外的判断
parent 20f466f9
......@@ -106,6 +106,16 @@
},
"homePlaces": {
"places": [
{
"images": [
"http://cdn.xinzhi.space/default/30FE64076B4C9E06F544BF175AC65983.jpg",
"http://cdn.xinzhi.space/default/DA8F94CCEAC8659BE383E49770ADD0E7.jpg",
"http://cdn.xinzhi.space/default/5522899728A44CFF8D44F92BA76A9E85.jpg"
],
"name": "北京故宫博物馆",
"latitude": 39.913959,
"longitude": 116.40399
},
{
"images": [
"http://cdn.xinzhi.space/default/CBCAD69A2EC1401E479F0BFC36B69C4D.jpg",
......@@ -126,16 +136,7 @@
"latitude": 28.192888,
"longitude": 112.968618
},
{
"images": [
"http://cdn.xinzhi.space/default/30FE64076B4C9E06F544BF175AC65983.jpg",
"http://cdn.xinzhi.space/default/DA8F94CCEAC8659BE383E49770ADD0E7.jpg",
"http://cdn.xinzhi.space/default/5522899728A44CFF8D44F92BA76A9E85.jpg"
],
"name": "北京故宫博物馆",
"latitude": 39.913959,
"longitude": 116.40399
},
{
"images": [
"http://cdn.xinzhi.space/default/5BEF22B14C879F3F686F3EAE9AB7C508.jpg",
......
......@@ -16,6 +16,8 @@ import com.baidu.location.LocationClient
import com.baidu.location.LocationClientOption
import com.baidu.mapapi.map.*
import com.baidu.mapapi.model.LatLng
import com.baidu.mapapi.search.core.SearchResult
import com.baidu.mapapi.search.geocode.*
import com.fry.base.base.BaseFragment
import com.google.gson.Gson
import com.mints.street.BR
......@@ -24,13 +26,13 @@ import com.mints.street.bean.MapBean
import com.mints.street.bean.PositioningBean
import com.mints.street.databinding.FragmentHomeBinding
import com.mints.street.manager.UmengManager
import com.mints.street.utils.GPSConverterUtils
import com.mints.street.widget.ScrollLayout
import com.mints.street.widget.dialog.DialogUtils
import me.goldze.mvvmhabit.base.AppManager
import me.goldze.mvvmhabit.utils.KLog
import me.goldze.mvvmhabit.utils.RxUtils
import me.goldze.mvvmhabit.utils.SPUtils
import me.goldze.mvvmhabit.utils.ToastUtils
/**
* Created by 冯瑞雨 on 2021/7/2.
......@@ -74,6 +76,9 @@ class HomeFragment : BaseFragment<FragmentHomeBinding, HomeViewModel>(), SensorE
//设置定位数据的精度信息,单位:米
private var mCurrentAccracy = 0f
//当前地图放大缩小的级别
private var currentMapZoom = 0F
// 是否首次定位
private var isFirstLoc = true
private var myLocationData: MyLocationData? = null
......@@ -102,6 +107,7 @@ class HomeFragment : BaseFragment<FragmentHomeBinding, HomeViewModel>(), SensorE
override fun initData() {
super.initData()
geoCoder()
Handler().postDelayed({ isScrollLayoutClose = true }, 2000)
RxUtils.onMultiClick(binding.stbBgSearch) {
SearchMapActivity.startSearchMapActivity(this)
......@@ -137,7 +143,7 @@ class HomeFragment : BaseFragment<FragmentHomeBinding, HomeViewModel>(), SensorE
// 默认 天安门
val center = LatLng(39.915071, 116.403907)
// 默认 11级
val zoom = 11.0f
val zoom = 14.0f
builder.target(center).zoom(zoom)
val mapStatusUpdate = MapStatusUpdateFactory.newMapStatus(builder.build())
......@@ -160,21 +166,26 @@ class HomeFragment : BaseFragment<FragmentHomeBinding, HomeViewModel>(), SensorE
binding.scrollLayout.toggle(ScrollLayout.STATUS_CLOSE)
}
}
}
override fun onMapStatusChangeFinish(status: MapStatus?) {
KLog.a("百度map", "移动结束")
currentLat = status?.target?.latitude ?: 0.0
currentLon = status?.target?.longitude ?: 0.0
currentMapZoom = status?.zoom?:0f
// 发起反地理编码请求
mSearch.reverseGeoCode(ReverseGeoCodeOption().location(status?.target))
}
})
//使地图缩放级别增大一级
binding.imageIn.setOnClickListener {
mBaiduMap?.setMapStatus(MapStatusUpdateFactory.zoomIn())
mBaiduMap?.animateMapStatus(MapStatusUpdateFactory.zoomIn(),300)
}
//使地图缩放级别减小一级
binding.imageOut.setOnClickListener {
mBaiduMap?.setMapStatus(MapStatusUpdateFactory.zoomOut())
mBaiduMap?.animateMapStatus(MapStatusUpdateFactory.zoomOut(),300)
}
//历史影像
binding.imageMapHistory.setOnClickListener {
......@@ -185,12 +196,12 @@ class HomeFragment : BaseFragment<FragmentHomeBinding, HomeViewModel>(), SensorE
// 默认 天安门
val center = LatLng(mCurrentLat, mCurrentLon)
// 默认 11级
val zoom = 17.0f
val zoom = 14.0f
builder.target(center).zoom(zoom)
val mapStatusUpdate = MapStatusUpdateFactory.newMapStatus(builder.build())
// 设置地图状态
mBaiduMap?.setMapStatus(mapStatusUpdate)
mBaiduMap?.animateMapStatus(mapStatusUpdate,300)
}
//定位初始化
initLocation()
......@@ -229,6 +240,56 @@ class HomeFragment : BaseFragment<FragmentHomeBinding, HomeViewModel>(), SensorE
mLocClient?.locOption = option
mLocClient?.start()
}
/**
*逆地理编码
*/
val mSearch = GeoCoder.newInstance()
private fun geoCoder(){
val listener: OnGetGeoCoderResultListener = object : OnGetGeoCoderResultListener{
override fun onGetGeoCodeResult(p0: GeoCodeResult?) {
}
override fun onGetReverseGeoCodeResult(reverseGeoCodeResult : ReverseGeoCodeResult?) {
if (reverseGeoCodeResult == null || reverseGeoCodeResult.error !== SearchResult.ERRORNO.NO_ERROR) {
//没有找到检索结果
return
} else {
if ("CN".equals(reverseGeoCodeResult.addressDetail.countryCodeIso2)){
if(currentMapZoom >= 15){
ToastUtils.showLong("请充值升级会员")
var zoom = 13f
// 默认 天安门
val center = LatLng(currentLat, currentLon)
// 默认 11级
val builder = MapStatus.Builder()
builder.target(center).zoom(zoom)
val mapStatusUpdate = MapStatusUpdateFactory.newMapStatus(builder.build())
// 设置地图状态
mBaiduMap?.animateMapStatus(mapStatusUpdate,200)
}
}else{
ToastUtils.showLong("请充值升级会员")
var zoom = 13f
// 默认 天安门
val center = LatLng(mCurrentLat, mCurrentLon)
// 默认 11级
val builder = MapStatus.Builder()
builder.target(center).zoom(zoom)
val mapStatusUpdate = MapStatusUpdateFactory.newMapStatus(builder.build())
// 设置地图状态
mBaiduMap?.animateMapStatus(mapStatusUpdate,500)
}
}
}
}
mSearch.setOnGetGeoCodeResultListener(listener)
}
override fun onPause() {
......@@ -299,7 +360,7 @@ class HomeFragment : BaseFragment<FragmentHomeBinding, HomeViewModel>(), SensorE
isFirstLoc = false
val ll = LatLng(location?.latitude?:0.0, location?.longitude?:0.0)
val builder = MapStatus.Builder()
builder.target(ll).zoom(18.0f)
builder.target(ll).zoom(14.0f)
this.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build()))
}
}
......@@ -336,7 +397,7 @@ class HomeFragment : BaseFragment<FragmentHomeBinding, HomeViewModel>(), SensorE
val builder = MapStatus.Builder()
builder.target(latLng).zoom(18.5f).overlook(-21f).rotate(0f)
// 更新地图状态
mBaiduMap!!.setMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build()))
mBaiduMap!!.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build()),300)
//mMarker.setPosition(latLng)
}
}
\ No newline at end of file
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