高德地图显示单个窗体和显示多个窗体的方法

2019-02-27  本文已影响0人  androidfan

高德地图是我经常使用过的组件,今天想跟大家讨论下信息窗体的创建与显示的方法,这种就是属于自定的内容了,需要到高德开发者中心查看一些相应的文档


image.png
LatLng latLng = new LatLng(39.906901,116.397972);
final Marker marker = aMap.addMarker(new MarkerOptions().position(latLng).title("北京").snippet("DefaultMarker"));

官方是只有这寥寥数语,个中意味需要开发者仔细研究


image.png

经过我的而不断探索,最终吧还是搞懂了,其实这都是之前做好的,今天总结出来学习(装逼)而已,哈哈


class BubbleInfoUpActivity : BaseActivity(), LocationSource, AMapLocationListener, AMap.InfoWindowAdapter,
        AMap.OnInfoWindowClickListener, AMap.OnCameraChangeListener {



    //省略若干无用代码




    override fun onLocationChanged(aMapLocation: AMapLocation) {
    }

    override fun getInfoWindow(marker: Marker?): View {
        var infoWindow = LayoutInflater.from(this@BubbleInfoUpActivity).inflate(R.layout.layout_gd_map_distance, null)
        var name = infoWindow.findViewById<TextView>(R.id.gd_distance)
        name.text = "我在这里"
        marker?.isVisible = true
        return infoWindow

    }

    override fun getInfoContents(marker: Marker?): View? {
        return null
    }

    override fun onInfoWindowClick(marker: Marker?) {
        marker?.isVisible = true
        marker?.showInfoWindow()

    }

    override fun activate(onLocationChangedListener: LocationSource.OnLocationChangedListener) {

    }

    override fun deactivate() {

    }

    override fun onCameraChange(cameraPosition: CameraPosition) {

    }

    override fun onCameraChangeFinish(cameraPosition: CameraPosition) {
        val infoWindowAnimationManager = aMap?.infoWindowAnimationManager
        infoWindowAnimationManager?.startAnimation()
        mMarker?.showInfoWindow()
        mMarker?.isInfoWindowEnable = true
        onInfoWindowClick(mMarker)
    }




}

Ok,就是这样,实现这几个接口,然后就能在一个定位点上显示一个小的信息窗体了,至于窗体的形状样式,自己可以在layout_gd_map_distance里更改

我们还是直接看代码

        aMap?.myLocationStyle = myLocationStyle
        //实例化UiSettings类对象
        mUiSettings = aMap?.uiSettings
        //不显示缩放按钮
        mUiSettings?.isZoomControlsEnabled = false
        //不显示我的位置
        myLocationStyle.showMyLocation(false)
        // 设置默认定位按钮是否显示
        aMap?.uiSettings?.isMyLocationButtonEnabled = false
        aMap?.isMyLocationEnabled = false
        //自定义InfoWindow
        aMap?.setInfoWindowAdapter(this)//AMap类中
        aMap?.setOnInfoWindowClickListener(this)
        //自己的位置
        val latLng = LatLng(worker_lat, worker_lon)
        mMarker = aMap?.addMarker(MarkerOptions().position(latLng)
                .title("运送位置")
                .snippet("运送位置")
                .setFlat(true)
                .icon(getBitamap()))
//             .icon(BitmapDescriptorFactory.fromResource(R.drawable.new_location_icon)))

最重要的就是这个icon方法了

    private fun getBitamap(): BitmapDescriptor? {
        var view = LayoutInflater.from(this@BubbleInfoUpActivity).inflate(R.layout.layout_title, null)
        return BitmapDescriptorFactory.fromView(view)


    }

Ok,想要什么样的弹窗就自己添加就好了
以上呢就是添加弹窗的两种方法,"砖厂繁忙,告辞了",搬砖码字去了。

上一篇 下一篇

猜你喜欢

热点阅读