Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
p x
MapMultiEngine
Commits
10c3f320
Commit
10c3f320
authored
Jul 21, 2025
by
p x
Browse files
做到逆地理编码
parent
a4c149a6
Changes
16
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/com/sd/mapmultiengine/MainActivity.kt
View file @
10c3f320
...
@@ -6,6 +6,14 @@ import androidx.appcompat.app.AppCompatActivity
...
@@ -6,6 +6,14 @@ import androidx.appcompat.app.AppCompatActivity
import
com.sd.maplibrary.MAP_TYPE
import
com.sd.maplibrary.MAP_TYPE
import
com.sd.maplibrary.MSDKInitializer
import
com.sd.maplibrary.MSDKInitializer
import
com.sd.maplibrary.OnSdkInitCb
import
com.sd.maplibrary.OnSdkInitCb
import
com.sd.maplibrary.bean.MSLatLng
import
com.sd.maplibrary.bean.PoiSearchRes
import
com.sd.maplibrary.bean.RegeocodeRes
import
com.sd.maplibrary.core.MSCanvesInMap
import
com.sd.maplibrary.core.MSGestures
import
com.sd.maplibrary.core.MSMethodAdv
import
com.sd.maplibrary.core.MSPoiSearch
import
com.sd.maplibrary.core.MSRegeoCode
import
com.sd.maplibrary.core.MapReadyView
import
com.sd.maplibrary.core.MapReadyView
import
com.sd.maplibrary.ui.MapMultiView.OnMapReadyLis
import
com.sd.maplibrary.ui.MapMultiView.OnMapReadyLis
import
com.sd.maplibrary.vms.MainVM
import
com.sd.maplibrary.vms.MainVM
...
@@ -31,30 +39,105 @@ class MainActivity : AppCompatActivity() {
...
@@ -31,30 +39,105 @@ class MainActivity : AppCompatActivity() {
// insets
// insets
// }
// }
initMap
()
initMap
()
test
()
}
fun
test
()
{
binding
.
mapMultiView
.
addMapRenderCallback
(
object
:
OnMapReadyLis
{
binding
.
mapMultiView
.
addMapRenderCallback
(
object
:
OnMapReadyLis
{
override
fun
onMapReady
(
mapReadyView
:
MapReadyView
)
{
override
fun
onMapReady
(
mapReadyView
:
MapReadyView
)
{
this
@MainActivity
.
mapReadView
=
mapReadyView
this
@MainActivity
.
mapReadView
=
mapReadyView
//显示定位蓝点
test
()
mainVM
.
showMyLocLandian
(
this
@MainActivity
.
mapReadView
)
}
}
})
})
jumpAct
()
}
private
fun
jumpAct
()
{
binding
.
btSeartch
.
setOnClickListener
{
}
}
fun
test
()
{
//显示定位蓝点
// mainVM.showMyLocLandian(this@MainActivity.mapReadView)
//手势交互
// MSGestures.setTiltGesturesEnabled(mapReadView!!,true)
//改变地图中心点
// MSMethodAdv.setMapCenter(mapReadView)
MSMethodAdv
.
setMapCenter
(
mapReadView
,
39.977290
,
116.337000
)
//改变缩放级别
MSMethodAdv
.
setMapZoom
(
mapReadView
,
10f
)
//绘制Marker点
MSCanvesInMap
.
dMarket
(
mapReadView
,
39.977290
,
116.337000
,
this
)
//绘制一条线
var
msLatLng
=
listOf
<
MSLatLng
>(
MSLatLng
(
39.999391
,
116.135972
),
MSLatLng
(
39.898323
,
116.057694
),
MSLatLng
(
39.900430
,
116.265061
),
MSLatLng
(
39.955192
,
116.140092
)
)
MSCanvesInMap
.
dPolyline
(
mapReadView
,
msLatLng
)
//绘制一个圆形
MSCanvesInMap
.
dCircle
(
mapReadView
,
39.997290
,
116.337000
,
2000f
)
//绘制一个面
var
mspLatLng
=
listOf
<
MSLatLng
>(
MSLatLng
(
39.993391
,
116.135272
),
MSLatLng
(
39.808323
,
116.057604
),
MSLatLng
(
39.904430
,
116.265061
),
MSLatLng
(
39.950192
,
116.140002
)
)
MSCanvesInMap
.
dPolygon
(
mapReadView
,
mspLatLng
)
//Poi搜索
// testPoiSearch()
//POi范围搜索
// testPoiSearchBound()
//逆地理编码
MSRegeoCode
.
geoCoder
(
this
,
41.80196
,
123.43326
,
object
:
MSRegeoCode
.
MSOnRegeo
{
override
fun
onRegeo
(
regeocodeRes
:
RegeocodeRes
?)
{
var
a
=
0
}
})
}
//poi搜索
fun
testPoiSearch
()
{
MSPoiSearch
.
startPoiSearch
(
this
,
"北京大学"
,
41.80196
,
123.43326
,
object
:
MSPoiSearch
.
OnMSPoiSearchLis
{
override
fun
onPoiLis
(
poiList
:
List
<
PoiSearchRes
>,
resCode
:
Int
)
{
// println("------------poiList = ${poiList}")
}
})
}
//poi 范围搜索
fun
testPoiSearchBound
()
{
MSPoiSearch
.
startPoiSearchBound
(
this
,
"北京大学"
,
39.977290
,
116.337000
,
25000
,
object
:
MSPoiSearch
.
OnMSPoiSearchLis
{
override
fun
onPoiLis
(
poiList
:
List
<
PoiSearchRes
>,
resCode
:
Int
)
{
// println("------------poiList = ${poiList}")
}
})
}
}
fun
initMap
()
{
fun
initMap
()
{
MSDKInitializer
.
initializeMap
(
this
,
MAP_TYPE
.
MINE
,
object
:
OnSdkInitCb
{
MSDKInitializer
.
initializeMap
(
this
,
MAP_TYPE
.
AMAP
,
object
:
OnSdkInitCb
{
override
fun
onInitSuccess
()
{
override
fun
onInitSuccess
()
{
println
(
"--------onMapInitSuccess}"
)
println
(
"--------onMapInitSuccess}"
)
}
}
override
fun
onInitFailed
(
msg
:
String
)
{
override
fun
onInitFailed
(
msg
:
String
)
{
}
}
})
})
}
}
}
}
\ No newline at end of file
app/src/main/res/layout/activity_main.xml
View file @
10c3f320
...
@@ -5,12 +5,25 @@
...
@@ -5,12 +5,25 @@
android:layout_height=
"match_parent"
android:layout_height=
"match_parent"
android:orientation=
"vertical"
>
android:orientation=
"vertical"
>
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
>
<Button
android:id=
"@+id/bt_seartch"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"搜索"
/>
</LinearLayout>
<com.sd.maplibrary.ui.MapMultiView
<com.sd.maplibrary.ui.MapMultiView
android:id=
"@+id/mapMultiView"
android:id=
"@+id/mapMultiView"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:layout_height=
"match_parent"
app:map_type=
"
MINE
"
/>
app:map_type=
"
AMAP
"
/>
</LinearLayout>
</LinearLayout>
maplibrary/build.gradle.kts
View file @
10c3f320
...
@@ -54,8 +54,8 @@ dependencies {
...
@@ -54,8 +54,8 @@ dependencies {
androidTestImplementation
(
libs
.
androidx
.
espresso
.
core
)
androidTestImplementation
(
libs
.
androidx
.
espresso
.
core
)
//网络
//网络
//
implementation("com.squareup.
retrofit2:retrofit:2.9
.0")
implementation
(
"com.squareup.
okhttp3:okhttp:3.12
.0"
)
//
implementation("com.
squareup.retrofit2:converter-
gson:2.
9.0
")
implementation
(
"com.
google.code.gson:
gson:2.
8.6
"
)
// 权限请求框架
// 权限请求框架
implementation
(
"com.guolindev.permissionx:permissionx:1.8.1"
)
implementation
(
"com.guolindev.permissionx:permissionx:1.8.1"
)
// ViewModel
// ViewModel
...
...
maplibrary/src/main/java/com/sd/maplibrary/bean/MSLatLng.kt
0 → 100644
View file @
10c3f320
package
com.sd.maplibrary.bean
/**整合四维和高德的经纬度**/
class
MSLatLng
{
constructor
(
lat
:
Double
,
lng
:
Double
)
{
this
.
lat
=
lat
this
.
lng
=
lng
}
var
lat
=
0.0
var
lng
=
0.0
}
\ No newline at end of file
maplibrary/src/main/java/com/sd/maplibrary/bean/PoiSearchRes.kt
0 → 100644
View file @
10c3f320
package
com.sd.maplibrary.bean
/****POI 搜索返回**/
class
PoiSearchRes
{
var
lat
=
0.0
var
lng
=
0.0
var
cityName
=
""
//行政去编码
var
adCode
=
""
//POI的名称
var
title
=
""
//POI的地址
var
snippet
=
""
//POI距离中心点的距离。范围搜索才有
var
distance
=
0
}
\ No newline at end of file
maplibrary/src/main/java/com/sd/maplibrary/bean/RegeocodeRes.kt
0 → 100644
View file @
10c3f320
package
com.sd.maplibrary.bean
/***逆地理编码返回**/
class
RegeocodeRes
{
// 逆地理编码返回的所在省名称
var
province
=
""
// var provinceCode = ""
//逆地理编码返回的所在城市名称
var
city
=
""
var
cityCode
=
""
//逆地理编码返回的所在区(县)名称。
var
district
=
""
//逆地理编码返回的所在乡镇/街道。
var
town
=
""
//逆地理编码返回的所在村镇。
// var village = ""
}
\ No newline at end of file
maplibrary/src/main/java/com/sd/maplibrary/core/MSCanvesInMap.kt
0 → 100644
View file @
10c3f320
package
com.sd.maplibrary.core
import
android.content.Context
import
android.graphics.BitmapFactory
import
androidx.core.graphics.toColorInt
import
com.amap.api.maps.model.BitmapDescriptorFactory
import
com.minedata.minenavi.map.CircleOptions
import
com.minedata.minenavi.map.MarkerOptions
import
com.minedata.minenavi.map.PolygonOptions
import
com.minedata.minenavi.map.PolylineOptions
import
com.minedata.minenavi.mapdal.LatLng
import
com.sd.maplibrary.MAP_TYPE
import
com.sd.maplibrary.MSDKInitializer
import
com.sd.maplibrary.R
import
com.sd.maplibrary.bean.MSLatLng
import
com.amap.api.maps.model.CircleOptions
as
ACircleOptions
import
com.amap.api.maps.model.LatLng
as
ALatLng
import
com.amap.api.maps.model.MarkerOptions
as
AMarkerOptions
import
com.amap.api.maps.model.PolylineOptions
as
APolylineOptions
import
com.amap.api.maps.model.PolygonOptions
as
APolygonOptions
/*****在地图上绘制**/
object
MSCanvesInMap
{
/***绘制Market 点标记
* @param lat 纬度
* @param lng 经度
* ***/
fun
dMarket
(
mapReadView
:
MapReadyView
?,
lat
:
Double
,
lng
:
Double
,
context
:
Context
)
{
when
(
MSDKInitializer
.
getMapType
())
{
MAP_TYPE
.
MINE
->
{
val
icon
=
BitmapFactory
.
decodeResource
(
context
.
resources
,
R
.
drawable
.
market_loc
)
val
latLng
=
LatLng
(
lat
,
lng
)
var
options
=
MarkerOptions
()
.
zLevel
(
7
)
.
bitmap
(
icon
)
// 位置坐标
.
position
(
latLng
)
mapReadView
?.
mMineMap
?.
addMarker
(
options
)
}
MAP_TYPE
.
AMAP
->
{
val
aLatLng
=
ALatLng
(
lat
,
lng
)
val
aMarkerOption
=
AMarkerOptions
().
apply
{
position
(
aLatLng
)
icon
(
BitmapDescriptorFactory
.
fromBitmap
(
BitmapFactory
.
decodeResource
(
context
.
resources
,
R
.
drawable
.
market_loc
)
)
)
}
mapReadView
?.
aMap
?.
addMarker
(
aMarkerOption
)
}
}
}
/***绘制线
*@param width = 宽度
*@param fillColor = 填充颜色
*@param isDotted = 是否虚线
* ***/
fun
dPolyline
(
mapReadView
:
MapReadyView
?,
msLatLng
:
List
<
MSLatLng
>,
width
:
Float
=
20f
,
fillColor
:
Int
=
"#FF00FF"
.
toColorInt
(),
isDotted
:
Boolean
=
false
)
{
when
(
MSDKInitializer
.
getMapType
())
{
MAP_TYPE
.
MINE
->
{
var
latLngs
=
msLatLng
.
map
{
LatLng
(
it
.
lat
,
it
.
lng
)
}
var
options
=
PolylineOptions
()
// 添加顶点坐标
.
addAll
(
latLngs
)
.
width
(
width
)
.
color
(
fillColor
)
.
setDottedLine
(
isDotted
)
var
polyline
=
mapReadView
?.
mMineMap
?.
addPolyline
(
options
)
}
MAP_TYPE
.
AMAP
->
{
var
latLngs
=
msLatLng
.
map
{
ALatLng
(
it
.
lat
,
it
.
lng
)
}
val
aMarkerOption
=
APolylineOptions
().
addAll
(
latLngs
)
.
width
(
width
)
.
color
(
fillColor
)
.
setDottedLine
(
isDotted
)
var
polyline
=
mapReadView
?.
aMap
?.
addPolyline
(
aMarkerOption
)
}
}
}
/***绘制圆形****/
fun
dCircle
(
mapReadView
:
MapReadyView
?,
lat
:
Double
,
lng
:
Double
,
radius
:
Float
,
fillColor
:
Int
=
"#50FF0000"
.
toColorInt
(),
strokeColor
:
Int
=
"#500000FF"
.
toColorInt
(),
strokeWidth
:
Float
=
15f
)
{
when
(
MSDKInitializer
.
getMapType
())
{
MAP_TYPE
.
MINE
->
{
var
latLng
=
LatLng
(
lat
,
lng
)
val
options
=
CircleOptions
()
.
center
(
latLng
)
.
radius
(
radius
)
.
fillColor
(
fillColor
)
.
strokeColor
(
strokeColor
)
.
strokeWidth
(
strokeWidth
)
var
circle
=
mapReadView
?.
mMineMap
?.
addCircle
(
options
)
}
MAP_TYPE
.
AMAP
->
{
var
latLng
=
ALatLng
(
lat
,
lng
)
val
options
=
ACircleOptions
()
.
center
(
latLng
)
.
radius
(
radius
.
toDouble
())
.
fillColor
(
fillColor
)
.
strokeColor
(
strokeColor
)
.
strokeWidth
(
strokeWidth
)
var
circle
=
mapReadView
?.
aMap
?.
addCircle
(
options
)
}
}
}
/***
* 绘制多边形
* ****/
fun
dPolygon
(
mapReadView
:
MapReadyView
?,
msLatLng
:
List
<
MSLatLng
>,
fillColor
:
Int
=
"#10FF00FF"
.
toColorInt
(),
strokeWidth
:
Float
=
15f
,
strokeColor
:
Int
=
"#50FF00FF"
.
toColorInt
()
)
{
when
(
MSDKInitializer
.
getMapType
())
{
MAP_TYPE
.
MINE
->
{
var
latLngs
=
msLatLng
.
map
{
LatLng
(
it
.
lat
,
it
.
lng
)
}
// 声明 多边形参数对象
val
polygonOptions
=
PolygonOptions
().
apply
{
addAll
(
latLngs
)
fillColor
(
fillColor
)
strokeWidth
(
strokeWidth
)
strokeColor
(
strokeColor
)
}
var
polygon
=
mapReadView
?.
mMineMap
?.
addPolygon
(
polygonOptions
)
}
MAP_TYPE
.
AMAP
->
{
var
latLngs
=
msLatLng
.
map
{
ALatLng
(
it
.
lat
,
it
.
lng
)
}
val
aPolygonOptions
=
APolygonOptions
().
apply
{
addAll
(
latLngs
)
fillColor
(
fillColor
)
strokeWidth
(
strokeWidth
)
strokeColor
(
strokeColor
)
}
var
polygon
=
mapReadView
?.
aMap
?.
addPolygon
(
aPolygonOptions
)
}
}
}
// /****改变地图显示区域**/
// fun setMapZoom(mapReadView: MapReadyView?, zoom: Float=16f) {
// when (MSDKInitializer.getMapType()) {
// MAP_TYPE.MINE -> {
// mapReadView?.mMineMap?.setZoomLevel(zoom)
// }
//
// MAP_TYPE.AMAP -> {
// var mCameraUpdate = CameraUpdateFactory.zoomTo(zoom)
// mapReadView?.aMap?.moveCamera(mCameraUpdate)
// }
// }
// }
}
\ No newline at end of file
maplibrary/src/main/java/com/sd/maplibrary/core/MSGestures.kt
0 → 100644
View file @
10c3f320
package
com.sd.maplibrary.core
import
com.sd.maplibrary.MAP_TYPE
import
com.sd.maplibrary.MSDKInitializer
/***手势交互**/
object
MSGestures
{
//
// /***缩放**/
// fun setZoomGesturesEnabled(mapReadView: MapReadyView,enable: Boolean) {
// when (MSDKInitializer.getMapType()) {
// MAP_TYPE.MINE -> {
// mapReadView.fMapView?.zoomView.is
// }
//
// MAP_TYPE.AMAP -> {
// mapReadView.amap?.uiSettings?.setZoomGesturesEnabled(enable)
// }
// }
// }
/***旋转开关**/
fun
setRotateGesturesEnabled
(
mapReadView
:
MapReadyView
?,
enable
:
Boolean
)
{
when
(
MSDKInitializer
.
getMapType
())
{
MAP_TYPE
.
MINE
->
{
mapReadView
?.
fMapView
?.
uiSettings
?.
isRotateGesturesEnabled
=
enable
}
MAP_TYPE
.
AMAP
->
{
mapReadView
?.
aMap
?.
uiSettings
?.
isRotateGesturesEnabled
=
enable
}
}
}
/***倾斜开关**/
fun
setTiltGesturesEnabled
(
mapReadView
:
MapReadyView
?,
enable
:
Boolean
)
{
when
(
MSDKInitializer
.
getMapType
())
{
MAP_TYPE
.
MINE
->
{
mapReadView
?.
fMapView
?.
uiSettings
?.
isTiltGesturesEnabled
=
enable
}
MAP_TYPE
.
AMAP
->
{
mapReadView
?.
aMap
?.
uiSettings
?.
isTiltGesturesEnabled
=
enable
}
}
}
}
\ No newline at end of file
maplibrary/src/main/java/com/sd/maplibrary/core/MSLocationStyle.kt
View file @
10c3f320
...
@@ -28,23 +28,12 @@ object MSLocationStyle {
...
@@ -28,23 +28,12 @@ object MSLocationStyle {
LOCATION_TYPE_MAP_ROTATE_NO_CENTER
to
aMapMyLocationStyle
.
LOCATION_TYPE_MAP_ROTATE_NO_CENTER
LOCATION_TYPE_MAP_ROTATE_NO_CENTER
to
aMapMyLocationStyle
.
LOCATION_TYPE_MAP_ROTATE_NO_CENTER
)
)
// myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_SHOW);//只定位一次。
// myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATE) ;//定位一次,且将视角移动到地图中心点。
// myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_FOLLOW) ;//连续定位、且将视角移动到地图中心点,定位蓝点跟随设备移动。(1秒1次定位)
// myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_MAP_ROTATE);//连续定位、且将视角移动到地图中心点,地图依照设备方向旋转,定位点会跟随设备移动。(1秒1次定位)
// myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE);//连续定位、且将视角移动到地图中心点,定位点依照设备方向旋转,并且会跟随设备移动。(1秒1次定位)默认执行此种模式。
////以下三种模式从5.1.0版本开始提供
// myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE_NO_CENTER);//连续定位、蓝点不会移动到地图中心点,定位点依照设备方向旋转,并且蓝点会跟随设备移动。
// myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_FOLLOW_NO_CENTER);//连续定位、蓝点不会移动到地图中心点,并且蓝点会跟随设备移动。
// myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_MAP_ROTATE_NO_CENTER);//连续定位、蓝点不会移动到地图中心点,地图依照设备方向旋转,并且蓝点会跟随设备移动。
// 四维初始化定位蓝点样式类
// 四维初始化定位蓝点样式类
private
val
myLocationStyle
:
MyLocationStyle
by
lazy
{
MyLocationStyle
()
}
private
val
myLocationStyle
:
MyLocationStyle
by
lazy
{
MyLocationStyle
()
}
//高德初始化定位蓝点样式类
//高德初始化定位蓝点样式类
private
val
aMyLocationStyle
by
lazy
{
aMapMyLocationStyle
()
}
private
val
aMyLocationStyle
by
lazy
{
aMapMyLocationStyle
()
}
fun
setLocationStyle
(
mapReadView
:
MapReadyView
?,
type
:
Int
=
LOCATION_TYPE_LOCATION_ROTATE
)
{
fun
setLocationStyle
(
mapReadView
:
MapReadyView
?,
type
:
Int
=
LOCATION_TYPE_LOCATION_ROTATE
)
{
when
(
MSDKInitializer
.
getMapType
())
{
when
(
MSDKInitializer
.
getMapType
())
{
MAP_TYPE
.
MINE
->
{
MAP_TYPE
.
MINE
->
{
...
@@ -61,7 +50,7 @@ object MSLocationStyle {
...
@@ -61,7 +50,7 @@ object MSLocationStyle {
}
}
MAP_TYPE
.
AMAP
->
{
MAP_TYPE
.
AMAP
->
{
var
aMap
=
mapReadView
?.
a
m
ap
var
aMap
=
mapReadView
?.
a
M
ap
aMyLocationStyle
.
myLocationType
(
styleMap
.
get
(
type
)
!!
)
aMyLocationStyle
.
myLocationType
(
styleMap
.
get
(
type
)
!!
)
aMyLocationStyle
.
interval
(
2000
)
//设置连续定位模式下的定位间隔,只在连续定位模式下生效,单次定位模式下不会生效。单位为毫秒。
aMyLocationStyle
.
interval
(
2000
)
//设置连续定位模式下的定位间隔,只在连续定位模式下生效,单次定位模式下不会生效。单位为毫秒。
//aMap.getUiSettings().setMyLocationButtonEnabled(true);设置默认定位按钮是否显示,非必需设置。
//aMap.getUiSettings().setMyLocationButtonEnabled(true);设置默认定位按钮是否显示,非必需设置。
...
...
maplibrary/src/main/java/com/sd/maplibrary/core/MSMethodAdv.kt
0 → 100644
View file @
10c3f320
package
com.sd.maplibrary.core
import
com.amap.api.maps.CameraUpdateFactory
import
com.amap.api.maps.model.CameraPosition
import
com.amap.api.maps.model.LatLng
as
ALatLng
import
com.minedata.minenavi.mapdal.LatLng
import
com.minedata.minenavi.util.Tools
import
com.sd.maplibrary.MAP_TYPE
import
com.sd.maplibrary.MSDKInitializer
/****地图方法交互**/
object
MSMethodAdv
{
/****改变地图中心点**/
fun
setMapCenter
(
mapReadView
:
MapReadyView
?,
lat
:
Double
=
39.977290
,
lng
:
Double
=
116.337000
)
{
when
(
MSDKInitializer
.
getMapType
())
{
MAP_TYPE
.
MINE
->
{
val
point
=
Tools
.
latLngToPoint
(
LatLng
(
lat
,
lng
))
mapReadView
?.
mMineMap
?.
setPointToCenter
(
point
.
x
,
point
.
y
)
}
MAP_TYPE
.
AMAP
->
{
//参数依次是:视角调整区域的中心点坐标、希望调整到的缩放级别、俯仰角0°~45°(垂直与地图时为0)、偏航角 0~360° (正北方为0)
val
mCameraUpdate
=
CameraUpdateFactory
.
newCameraPosition
(
CameraPosition
(
ALatLng
(
lat
,
lng
),
18f
,
30f
,
0f
)
)
mapReadView
?.
aMap
?.
moveCamera
(
mCameraUpdate
)
}
}
}
/****改变地图缩放级别**/
fun
setMapZoom
(
mapReadView
:
MapReadyView
?,
zoom
:
Float
=
13f
)
{
when
(
MSDKInitializer
.
getMapType
())
{
MAP_TYPE
.
MINE
->
{
mapReadView
?.
mMineMap
?.
setZoomLevel
(
zoom
)
}
MAP_TYPE
.
AMAP
->
{
var
mCameraUpdate
=
CameraUpdateFactory
.
zoomTo
(
zoom
)
mapReadView
?.
aMap
?.
moveCamera
(
mCameraUpdate
)
}
}
}
// /****改变地图显示区域**/
// fun setMapZoom(mapReadView: MapReadyView?, zoom: Float=16f) {
// when (MSDKInitializer.getMapType()) {
// MAP_TYPE.MINE -> {
// mapReadView?.mMineMap?.setZoomLevel(zoom)
// }
//
// MAP_TYPE.AMAP -> {
// var mCameraUpdate = CameraUpdateFactory.zoomTo(zoom)
// mapReadView?.aMap?.moveCamera(mCameraUpdate)
// }
// }
// }
}
\ No newline at end of file
maplibrary/src/main/java/com/sd/maplibrary/core/MSPoiSearch.kt
0 → 100644
View file @
10c3f320
package
com.sd.maplibrary.core
import
android.content.Context
import
com.amap.api.services.core.AMapException
import
com.minedata.minenavi.mapdal.PoiItem
import
com.minedata.minenavi.poiquery.LatLonPoint
import
com.minedata.minenavi.poiquery.PoiResult
import
com.minedata.minenavi.poiquery.PoiSearch
import
com.minedata.minenavi.poiquery.SearchErrorCode
import
com.minedata.minenavi.poiquery.SortType
import
com.sd.maplibrary.MAP_TYPE
import
com.sd.maplibrary.MSDKInitializer
import
com.sd.maplibrary.bean.PoiSearchRes
import
com.amap.api.services.core.LatLonPoint
as
ALatLonPoint
import
com.amap.api.services.poisearch.PoiResult
as
APoiResult
import
com.amap.api.services.poisearch.PoiSearch
as
APoiSearch
import
com.amap.api.services.poisearch.PoiSearch.SearchBound
/****Poi 搜索相关**/
object
MSPoiSearch
:
PoiSearch
.
OnPoiSearchListener
,
APoiSearch
.
OnPoiSearchListener
{
private
var
onMSPoiSearchLis
:
OnMSPoiSearchLis
?
=
null
interface
OnMSPoiSearchLis
{
fun
onPoiLis
(
poiList
:
List
<
PoiSearchRes
>,
resCode
:
Int
)
}
/***关键字搜索
* @param lat 当期维度
* @param lng 当期经度
* ***/
fun
startPoiSearch
(
context
:
Context
,
keyWord
:
String
,
lat
:
Double
=
41.80196
,
lng
:
Double
=
123.43326
,
onMSPoiSearchLis
:
OnMSPoiSearchLis
)
{
this
.
onMSPoiSearchLis
=
onMSPoiSearchLis
when
(
MSDKInitializer
.
getMapType
())
{
MAP_TYPE
.
MINE
->
{
val
poiSearch
=
PoiSearch
(
context
)
poiSearch
.
setOnPoiSearchListener
(
this
)
val
query
=
PoiSearch
.
Query
(
keyWord
,
""
,
""
).
apply
{
// 设置查询位置点
location
=
LatLonPoint
(
lat
,
lng
)
// 限制严格按照设置城市搜索
setCityLimit
(
false
)
// 设置排序方式为热度排序
setSortType
(
SortType
.
SORT_TYPE_HIT
)
// 返回父子关系
requireSubPois
(
true
)
pageNum
=
0
setPageSize
(
20
)
// 设置每页最多返回多少条poiitem
}
poiSearch
.
query
=
query
poiSearch
.
searchPOIAsyn
()
}
MAP_TYPE
.
AMAP
->
{
var
query
=
APoiSearch
.
Query
(
keyWord
,
""
,
""
).
apply
{
location
=
ALatLonPoint
(
lat
,
lng
)
cityLimit
=
false
// 返回父子关系
requireSubPois
(
true
)
pageNum
=
1
pageSize
=
20
}
var
poiSearch
=
APoiSearch
(
context
,
query
)
poiSearch
.
setOnPoiSearchListener
(
this
)
poiSearch
.
searchPOIAsyn
()
}
}
}
/****周边搜索**/
fun
startPoiSearchBound
(
context
:
Context
,
keyWord
:
String
,
lat
:
Double
,
lng
:
Double
,
radios
:
Int
,
onMSPoiSearchLis
:
OnMSPoiSearchLis
)
{
this
.
onMSPoiSearchLis
=
onMSPoiSearchLis
when
(
MSDKInitializer
.
getMapType
())
{
MAP_TYPE
.
MINE
->
{
val
poiSearch
=
PoiSearch
(
context
)
poiSearch
.
setOnPoiSearchListener
(
this
)
// 第一个参数表示搜索中心点, 第二个参数表示搜索半径
val
bound
=
PoiSearch
.
SearchBound
(
LatLonPoint
(
lat
,
lng
),
radios
)
poiSearch
.
setBound
(
bound
)
// 第一个参数表示搜索关键字(可传空字符串),
// 第二个参数表示 POI 搜索类型,不同类型用|分割,
// 第三个参数表示 POI 搜索城市编码
val
query
=
PoiSearch
.
Query
(
keyWord
,
""
,
""
).
apply
{
// 设置查询位置点
location
=
LatLonPoint
(
lat
,
lng
)
// 限制严格按照设置城市搜索
setCityLimit
(
true
)
// 设置排序方式为热度排序
setSortType
(
SortType
.
SORT_TYPE_HIT
)
// 返回父子关系
requireSubPois
(
true
)
pageNum
=
0
setPageSize
(
20
)
// 设置每页最多返回多少条poiitem
}
poiSearch
.
query
=
query
poiSearch
.
searchPOIAsyn
()
}
MAP_TYPE
.
AMAP
->
{
var
query
=
APoiSearch
.
Query
(
keyWord
,
""
,
""
).
apply
{
location
=
ALatLonPoint
(
lat
,
lng
)
cityLimit
=
true
// 返回父子关系
requireSubPois
(
true
)
pageNum
=
1
pageSize
=
20
}
var
poiSearch
=
APoiSearch
(
context
,
query
)
poiSearch
.
setOnPoiSearchListener
(
this
)
poiSearch
.
setBound
(
SearchBound
(
ALatLonPoint
(
lat
,
lng
),
radios
,
true
))
poiSearch
.
searchPOIAsyn
()
}
}
}
//---------------------------------四维POI 返回 -------------------------------
override
fun
onPoiItemSearched
(
p0
:
PoiItem
?,
p1
:
Int
)
{
var
b
=
0
}
override
fun
onPoiSearched
(
result
:
PoiResult
?,
rCode
:
Int
)
{
if
(
rCode
==
SearchErrorCode
.
none
)
{
var
temps
=
result
?.
getPois
()
var
poiList
=
temps
!!
.
map
{
pos
->
PoiSearchRes
().
apply
{
lat
=
pos
.
location
.
latitude
lng
=
pos
.
location
.
longitude
title
=
pos
.
title
snippet
=
pos
.
snippet
cityName
=
pos
.
cityName
//这里为0 因为不是范围搜索
distance
=
pos
.
distance
adCode
=
pos
.
adCode
}
}
onMSPoiSearchLis
?.
onPoiLis
(
poiList
,
rCode
)
}
else
{
onMSPoiSearchLis
?.
onPoiLis
(
listOf
(),
rCode
)
}
}
//--------------------------------高德POI 搜索- -------------------------------
override
fun
onPoiSearched
(
result
:
APoiResult
?,
rCode
:
Int
)
{
if
(
rCode
==
AMapException
.
CODE_AMAP_SUCCESS
)
{
if
(
result
!=
null
&&
result
.
getQuery
()
!=
null
)
{
// 搜索poi的结果
var
temps
=
result
?.
getPois
()
var
poiList
=
temps
!!
.
map
{
pos
->
PoiSearchRes
().
apply
{
lat
=
pos
.
latLonPoint
.
latitude
lng
=
pos
.
latLonPoint
.
longitude
title
=
pos
.
title
snippet
=
pos
.
snippet
cityName
=
pos
.
cityName
//这里为0 因为不是范围搜索
distance
=
pos
.
distance
adCode
=
pos
.
adCode
}
}
onMSPoiSearchLis
?.
onPoiLis
(
poiList
,
rCode
)
}
}
else
{
onMSPoiSearchLis
?.
onPoiLis
(
listOf
(),
rCode
)
}
}
override
fun
onPoiItemSearched
(
p0
:
com
.
amap
.
api
.
services
.
core
.
PoiItem
?,
p1
:
Int
)
{
}
}
\ No newline at end of file
maplibrary/src/main/java/com/sd/maplibrary/core/MSRegeoCode.kt
0 → 100644
View file @
10c3f320
package
com.sd.maplibrary.core
import
android.content.Context
import
com.minedata.minenavi.poiquery.GeocodeResult
import
com.minedata.minenavi.poiquery.GeocodeSearch
import
com.minedata.minenavi.poiquery.LatLonPoint
import
com.minedata.minenavi.poiquery.RegeocodeQuery
import
com.minedata.minenavi.poiquery.RegeocodeResult
import
com.sd.maplibrary.MAP_TYPE
import
com.sd.maplibrary.MSDKInitializer
import
com.sd.maplibrary.bean.RegeocodeRes
import
com.amap.api.services.geocoder.RegeocodeQuery
as
ARegeocodeQuery
import
com.amap.api.services.core.LatLonPoint
as
ALatLonPoint
import
com.amap.api.services.geocoder.GeocodeSearch
as
AGeocodeSearch
import
com.amap.api.services.geocoder.RegeocodeResult
as
ARegeocodeResult
import
com.amap.api.services.core.AMapException
/***逆地理编码**/
object
MSRegeoCode
:
GeocodeSearch
.
OnGeocodeSearchListener
,
AGeocodeSearch
.
OnGeocodeSearchListener
{
private
var
mSOnRegeo
:
MSOnRegeo
?
=
null
interface
MSOnRegeo
{
fun
onRegeo
(
regeocodeRes
:
RegeocodeRes
?)
}
/****逆地理编码***/
fun
geoCoder
(
context
:
Context
,
lat
:
Double
,
lng
:
Double
,
msOnRegeo
:
MSOnRegeo
)
{
if
(
lat
==
0.0
||
lng
==
0.0
)
return
this
.
mSOnRegeo
=
msOnRegeo
when
(
MSDKInitializer
.
getMapType
())
{
MAP_TYPE
.
MINE
->
{
val
geocoderSearch
=
GeocodeSearch
(
context
)
geocoderSearch
.
setOnGeocodeSearchListener
(
this
)
// 参数表示地理坐标点
val
query
=
RegeocodeQuery
(
LatLonPoint
(
lat
,
lng
))
geocoderSearch
.
getFromLocationAsyn
(
query
)
}
MAP_TYPE
.
AMAP
->
{
// 第一个参数表示一个Latlng,第二参数表示范围多少米,第三个参数表示是火系坐标系还是GPS原生坐标系
val
query
=
ARegeocodeQuery
(
ALatLonPoint
(
lat
,
lng
),
200f
,
AGeocodeSearch
.
AMAP
)
var
geocoderSearch
=
AGeocodeSearch
(
context
)
geocoderSearch
.
setOnGeocodeSearchListener
(
this
);
geocoderSearch
.
getFromLocationAsyn
(
query
)
// 设置异步逆地理编码请求
}
}
}
//-------------------------- 四维 回调----------------------------------
override
fun
onGeocodeSearched
(
p0
:
GeocodeResult
?,
p1
:
Int
)
{
}
override
fun
onRegeocodeSearched
(
regeocodeResult
:
RegeocodeResult
?,
resultID
:
Int
)
{
// 解析 regeocodeResult 获取的逆地理编码信息
if
(!
regeocodeResult
?.
regeocodeAddressList
.
isNullOrEmpty
())
{
var
temp
=
regeocodeResult
.
regeocodeAddressList
.
first
()
var
regeocodeRes
=
RegeocodeRes
().
apply
{
province
=
temp
.
province
// provinceCode = temp.provinceCode
city
=
temp
.
city
cityCode
=
temp
.
cityCode
district
=
temp
.
district
town
=
temp
.
town
// village = temp.village
}
mSOnRegeo
?.
onRegeo
(
regeocodeRes
)
}
else
{
mSOnRegeo
?.
onRegeo
(
null
)
}
}
//-------------------------- 高德 回调----------------------------------
/**
* 逆地理编码回调
*/
override
fun
onRegeocodeSearched
(
result
:
ARegeocodeResult
?,
rCode
:
Int
)
{
if
(
rCode
==
AMapException
.
CODE_AMAP_SUCCESS
)
{
var
temp
=
result
!!
.
getRegeocodeAddress
()
var
regeocodeRes
=
RegeocodeRes
().
apply
{
province
=
temp
.
province
// provinceCode = temp.province
city
=
temp
.
city
cityCode
=
temp
.
cityCode
district
=
temp
.
district
town
=
temp
.
township
// village = temp.village
}
mSOnRegeo
?.
onRegeo
(
regeocodeRes
)
}
else
{
mSOnRegeo
?.
onRegeo
(
null
)
}
}
override
fun
onGeocodeSearched
(
p0
:
com
.
amap
.
api
.
services
.
geocoder
.
GeocodeResult
?,
p1
:
Int
)
{
}
}
\ No newline at end of file
maplibrary/src/main/java/com/sd/maplibrary/core/MapReadyView.kt
View file @
10c3f320
package
com.sd.maplibrary.core
package
com.sd.maplibrary.core
import
com.amap.api.maps.AMap
import
com.amap.api.maps.AMap
import
com.minedata.minenavi.map.MapView
import
com.minedata.minenavi.map.MineMap
import
com.minedata.minenavi.map.MineMap
/***地图准备就绪**/
class
MapReadyView
private
constructor
(){
class
MapReadyView
private
constructor
(){
companion
object
{
companion
object
{
val
instance
by
lazy
{
MapReadyView
()
}
val
instance
by
lazy
{
MapReadyView
()
}
}
}
var
fMapView
:
MapView
?
=
null
var
mMineMap
:
MineMap
?
=
null
var
mMineMap
:
MineMap
?
=
null
var
amap
:
AMap
?
=
null
//高德
var
aMap
:
AMap
?
=
null
}
}
\ No newline at end of file
maplibrary/src/main/java/com/sd/maplibrary/fragments/AMapFragment.kt
View file @
10c3f320
...
@@ -8,7 +8,6 @@ import androidx.fragment.app.Fragment
...
@@ -8,7 +8,6 @@ import androidx.fragment.app.Fragment
import
com.amap.api.maps.AMap
import
com.amap.api.maps.AMap
import
com.sd.maplibrary.core.MapReadyView
import
com.sd.maplibrary.core.MapReadyView
import
com.sd.maplibrary.databinding.FragmentAMapBinding
import
com.sd.maplibrary.databinding.FragmentAMapBinding
import
com.sd.maplibrary.ui.MapMultiView
import
com.sd.maplibrary.ui.MapMultiView.OnMapReadyLis
import
com.sd.maplibrary.ui.MapMultiView.OnMapReadyLis
...
@@ -52,7 +51,7 @@ class AMapFragment : Fragment() {
...
@@ -52,7 +51,7 @@ class AMapFragment : Fragment() {
super
.
onViewCreated
(
view
,
savedInstanceState
)
super
.
onViewCreated
(
view
,
savedInstanceState
)
binding
.
mMapView
.
onCreate
(
savedInstanceState
)
binding
.
mMapView
.
onCreate
(
savedInstanceState
)
aMap
=
binding
.
mMapView
.
map
aMap
=
binding
.
mMapView
.
map
MapReadyView
.
instance
.
a
m
ap
=
aMap
MapReadyView
.
instance
.
a
M
ap
=
aMap
onMapReadyLis
?.
onMapReady
(
MapReadyView
.
instance
)
onMapReadyLis
?.
onMapReady
(
MapReadyView
.
instance
)
}
}
...
...
maplibrary/src/main/java/com/sd/maplibrary/fragments/ForeMapFragment.kt
View file @
10c3f320
...
@@ -74,6 +74,7 @@ class ForeMapFragment : Fragment() {
...
@@ -74,6 +74,7 @@ class ForeMapFragment : Fragment() {
binding
.
mapView
.
addMapRenderCallback
{
mineMap
->
binding
.
mapView
.
addMapRenderCallback
{
mineMap
->
this
.
mMineMap
=
mineMap
this
.
mMineMap
=
mineMap
MapReadyView
.
instance
.
mMineMap
=
mineMap
MapReadyView
.
instance
.
mMineMap
=
mineMap
MapReadyView
.
instance
.
fMapView
=
binding
.
mapView
onMapReadyLis
?.
onMapReady
(
MapReadyView
.
instance
)
onMapReadyLis
?.
onMapReady
(
MapReadyView
.
instance
)
}
}
}
}
...
...
maplibrary/src/main/res/drawable-xhdpi/market_loc.png
0 → 100644
View file @
10c3f320
796 Bytes
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment