逆地理编码
This commit is contained in:
@@ -497,7 +497,7 @@ public class AMapNaviViewWrapper implements IMogoMapView,
|
||||
}
|
||||
|
||||
@Override
|
||||
public MogoLatLng getTarget() {
|
||||
public MogoLatLng getWindowCenterLocation() {
|
||||
try {
|
||||
return ObjectUtils.fromAMap( mMapView.getMap().getCameraPosition().target );
|
||||
} catch ( Exception e ) {
|
||||
|
||||
@@ -132,7 +132,7 @@ public class AMapUIController implements IMogoMapUIController {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override public MogoLatLng getTarget() {
|
||||
@Override public MogoLatLng getWindowCenterLocation() {
|
||||
if ( mClient != null ) {
|
||||
return mClient.getCameraSouthWestPosition();
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ public interface IMogoMapUIController {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
MogoLatLng getTarget();
|
||||
MogoLatLng getWindowCenterLocation();
|
||||
|
||||
/**
|
||||
* 设置地图中心点
|
||||
|
||||
@@ -125,9 +125,9 @@ public class MogoMapUIController implements IMogoMapUIController {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override public MogoLatLng getTarget() {
|
||||
@Override public MogoLatLng getWindowCenterLocation() {
|
||||
if (mDelegate != null) {
|
||||
return mDelegate.getTarget();
|
||||
return mDelegate.getWindowCenterLocation();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -5,8 +5,10 @@ import android.app.StatusBarManager
|
||||
import android.content.Context
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.alibaba.android.arouter.launcher.ARouter
|
||||
import com.amap.api.services.interfaces.IGeocodeSearch
|
||||
import com.mogo.map.marker.IMogoMarkerManager
|
||||
import com.mogo.map.navi.IMogoNavi
|
||||
import com.mogo.map.search.geo.IMogoGeoSearch
|
||||
import com.mogo.map.uicontroller.IMogoMapUIController
|
||||
import com.mogo.service.MogoServicePaths
|
||||
import com.mogo.service.fragmentmanager.FragmentDescriptor
|
||||
@@ -22,28 +24,28 @@ import kotlin.isInitialized as isInitialized1
|
||||
*/
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
object SearchServiceHolder {
|
||||
// 单例对象,要使用Application Context
|
||||
// 单例对象,要使用Application Context
|
||||
private lateinit var context: Context
|
||||
val fragmentManager:IMogoFragmentManager = ARouter.getInstance().build(
|
||||
val fragmentManager: IMogoFragmentManager = ARouter.getInstance().build(
|
||||
MogoServicePaths.PATH_FRAGMENT_MANAGER
|
||||
).navigation() as IMogoFragmentManager
|
||||
val mapService:IMogoMapService = ARouter.getInstance().build(
|
||||
val mapService: IMogoMapService = ARouter.getInstance().build(
|
||||
MogoServicePaths.PATH_SERVICES_MAP
|
||||
).navigation() as IMogoMapService
|
||||
val listenerCenter:IMogoRegisterCenter = ARouter.getInstance().build(
|
||||
val listenerCenter: IMogoRegisterCenter = ARouter.getInstance().build(
|
||||
MogoServicePaths.PATH_REGISTER_CENTER
|
||||
).navigation() as IMogoRegisterCenter
|
||||
val statusManager:IMogoStatusManager = ARouter.getInstance().build(
|
||||
MogoServicePaths.PATH_STATUS_MANAGER
|
||||
val statusManager: IMogoStatusManager = ARouter.getInstance().build(
|
||||
MogoServicePaths.PATH_STATUS_MANAGER
|
||||
).navigation() as IMogoStatusManager
|
||||
|
||||
var geoSearch: IMogoGeoSearch? = null
|
||||
|
||||
|
||||
fun init(context: Context){
|
||||
this.context=context
|
||||
fun init(context: Context) {
|
||||
this.context = context
|
||||
}
|
||||
|
||||
fun push(
|
||||
fun push(
|
||||
fragment: Fragment,
|
||||
tag: String
|
||||
) {
|
||||
@@ -54,8 +56,7 @@ object SearchServiceHolder {
|
||||
fragmentManager.push(build)
|
||||
}
|
||||
|
||||
|
||||
fun getNavi():IMogoNavi{
|
||||
fun getNavi(): IMogoNavi {
|
||||
return mapService.getNavi(context)
|
||||
}
|
||||
|
||||
@@ -63,10 +64,15 @@ object SearchServiceHolder {
|
||||
return mapService.mapUIController
|
||||
}
|
||||
|
||||
|
||||
|
||||
fun getMarkerManger():IMogoMarkerManager{
|
||||
fun getMarkerManger(): IMogoMarkerManager {
|
||||
return mapService.getMarkerManager(context)
|
||||
}
|
||||
|
||||
fun getGeoSearcher(): IMogoGeoSearch {
|
||||
if (geoSearch == null) {
|
||||
geoSearch = mapService.getGeoSearch(context)
|
||||
}
|
||||
return geoSearch!!
|
||||
}
|
||||
|
||||
}
|
||||
@@ -80,5 +80,19 @@ public abstract class BaseFragment extends Fragment {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 移动地图中心点到屏幕中心
|
||||
*/
|
||||
protected void moveMapToCenter(){
|
||||
SearchServiceHolder.INSTANCE.getMapUIController().setPointToCenter(0.5,0.5);
|
||||
}
|
||||
|
||||
//mMogoMapUIController.setPointToCenter( 0.66145, 0.590688 );
|
||||
/**
|
||||
* 移动地图中心点到屏幕右侧
|
||||
*/
|
||||
protected void moveMapToRight(){
|
||||
SearchServiceHolder.INSTANCE.getMapUIController().setPointToCenter(0.66145, 0.590688);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,13 +5,25 @@ import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.alibaba.android.arouter.facade.annotation.Route
|
||||
import com.mogo.map.MogoLatLng
|
||||
import com.mogo.map.listener.IMogoMapListener
|
||||
import com.mogo.map.location.IMogoLocationListener
|
||||
import com.mogo.map.location.MogoLocation
|
||||
import com.mogo.map.marker.IMogoMarker
|
||||
import com.mogo.map.marker.MogoMarkerOptions
|
||||
import com.mogo.map.search.geo.IMogoGeoSearchListener
|
||||
import com.mogo.map.search.geo.MogoGeocodeResult
|
||||
import com.mogo.map.search.geo.MogoRegeocodeResult
|
||||
import com.mogo.map.search.geo.query.MogoRegeocodeQuery
|
||||
import com.mogo.module.common.MogoModulePaths
|
||||
import com.mogo.module.common.adapter.MogoMapListenerAdapter
|
||||
import com.mogo.module.navi.R
|
||||
import com.mogo.module.navi.R.string
|
||||
import com.mogo.module.navi.constants.AMapConstants
|
||||
import com.mogo.module.navi.constants.SearchServiceHolder
|
||||
import com.mogo.module.navi.ui.base.BaseFragment
|
||||
import kotlinx.android.synthetic.main.fragment_setting_address.tv_set_as_home
|
||||
import kotlinx.android.synthetic.main.include_search_bar.et_navi_search
|
||||
import kotlinx.android.synthetic.main.include_search_bar.iv_navi_back
|
||||
|
||||
/**
|
||||
@@ -19,27 +31,49 @@ import kotlinx.android.synthetic.main.include_search_bar.iv_navi_back
|
||||
* 2020-01-07.
|
||||
*/
|
||||
@Route(path = MogoModulePaths.PATH_FRAGMENT_SETTING_HOME)
|
||||
class SettingAddressFragment : BaseFragment() {
|
||||
// override fun renderSearchPoiResult(
|
||||
// datums: MutableList<MogoTip>?,
|
||||
// showDelete: Boolean
|
||||
// ) {
|
||||
// mAdapter.setDatas(datums)
|
||||
// group_set_address.visibility = View.GONE
|
||||
// rv_search_result.visibility = View.VISIBLE
|
||||
//
|
||||
// }
|
||||
//
|
||||
// override fun showHistory(datums: MutableList<SearchPoi>?) {
|
||||
// }
|
||||
class SettingAddressFragment : BaseFragment(), IMogoGeoSearchListener {
|
||||
override fun onRegeocodeSearched(regeocodeResult: MogoRegeocodeResult?) {
|
||||
|
||||
private val TAG:String="SettingAddressFragment"
|
||||
et_navi_search.setText(regeocodeResult?.regeocodeAddress?.formatAddress)
|
||||
}
|
||||
|
||||
override fun onGeocodeSearched(geocodeResult: MogoGeocodeResult?) {
|
||||
|
||||
}
|
||||
|
||||
private val TAG: String = "SettingAddressFragment"
|
||||
private var style: Int = 0
|
||||
var addMarker: IMogoMarker? = null
|
||||
|
||||
private var mapListener: IMogoMapListener = object : MogoMapListenerAdapter() {
|
||||
override fun onMapChanged(
|
||||
latLng: MogoLatLng?,
|
||||
zoom: Float,
|
||||
tilt: Float,
|
||||
bearing: Float
|
||||
) {
|
||||
super.onMapChanged(latLng, zoom, tilt, bearing)
|
||||
var mogoRegeocodeQuery = MogoRegeocodeQuery()
|
||||
mogoRegeocodeQuery.point = latLng
|
||||
SearchServiceHolder.getGeoSearcher()
|
||||
.getFromLocationAsyn(mogoRegeocodeQuery)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
style = arguments?.getInt(AMapConstants.KEY_SET_HOME_COMPONY) ?: 0
|
||||
setMarkerStatus(true)
|
||||
SearchServiceHolder.getMapUIController().showMyLocation(false)
|
||||
SearchServiceHolder.listenerCenter.registerMogoMapListener(
|
||||
MogoModulePaths.PATH_FRAGMENT_SETTING_HOME, mapListener
|
||||
)
|
||||
SearchServiceHolder.getMapUIController()
|
||||
.showMyLocation(false)
|
||||
moveMapToCenter()
|
||||
|
||||
SearchServiceHolder.getGeoSearcher()
|
||||
.setGeoSearchListener(this)
|
||||
|
||||
}
|
||||
|
||||
@@ -55,8 +89,6 @@ class SettingAddressFragment : BaseFragment() {
|
||||
return style == 1
|
||||
}
|
||||
|
||||
|
||||
|
||||
override fun onViewCreated(
|
||||
view: View,
|
||||
savedInstanceState: Bundle?
|
||||
@@ -70,36 +102,44 @@ class SettingAddressFragment : BaseFragment() {
|
||||
tv_set_as_home.text = resources.getString(R.string.set_as_compony_navi)
|
||||
}
|
||||
|
||||
|
||||
|
||||
iv_navi_back.setOnClickListener {
|
||||
SearchServiceHolder.fragmentManager.pop()
|
||||
}
|
||||
|
||||
var target = SearchServiceHolder.getMapUIController()
|
||||
.target
|
||||
|
||||
var decodeResource = BitmapFactory.decodeResource(resources, R.mipmap.icon_choose_position)
|
||||
val options = MogoMarkerOptions()
|
||||
.icon(decodeResource)
|
||||
.latitude(target.lat.toDouble())
|
||||
.owner(TAG)
|
||||
.longitude(target.lng.toDouble())
|
||||
var addMarker = SearchServiceHolder.getMarkerManger()
|
||||
.addMarker(MogoModulePaths.PATH_FRAGMENT_SETTING_HOME, options)
|
||||
|
||||
|
||||
et_navi_search.isEnabled = false
|
||||
et_navi_search.setText(getString(string.drag_map_to_choose))
|
||||
var location = SearchServiceHolder.getMapUIController()
|
||||
.windowCenterLocation
|
||||
if (addMarker == null) {
|
||||
var decodeResource = BitmapFactory.decodeResource(resources, R.mipmap.icon_choose_position)
|
||||
val options = MogoMarkerOptions()
|
||||
.icon(decodeResource)
|
||||
.latitude(location?.lat ?: 0.0)
|
||||
.owner(TAG)
|
||||
.anchor(0.5f, 0.5f)
|
||||
.longitude(location?.lng ?: 0.0)
|
||||
addMarker = SearchServiceHolder.getMarkerManger()
|
||||
.addMarker(MogoModulePaths.PATH_FRAGMENT_SETTING_HOME, options)
|
||||
|
||||
var locationPointInScreen = SearchServiceHolder.getMapUIController()
|
||||
.getLocationPointInScreen(location)
|
||||
addMarker?.setPositionByPixels(locationPointInScreen)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
setMarkerStatus(true)
|
||||
SearchServiceHolder.getMapUIController().showMyLocation(true)
|
||||
SearchServiceHolder.getMapUIController()
|
||||
.showMyLocation(true)
|
||||
SearchServiceHolder.listenerCenter.unregisterMogoMapListener(
|
||||
MogoModulePaths.PATH_FRAGMENT_SETTING_HOME
|
||||
)
|
||||
addMarker?.destroy()
|
||||
moveMapToRight()
|
||||
}
|
||||
|
||||
|
||||
companion object {
|
||||
fun newInstance(type: Int = 0): Fragment {
|
||||
var settingAddressFragment = SettingAddressFragment()
|
||||
|
||||
@@ -33,4 +33,5 @@
|
||||
<string name="navi_to_there">导航去这里</string>
|
||||
<string name="start_navi">开始导航</string>
|
||||
<string name="choose_path">路线选择</string>
|
||||
<string name="drag_map_to_choose">拖动地图选点</string>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user