如何在停止仅在地图上拖动时获取LatLng。我需要像OLA Cab一样的功能

时间:2019-03-28 18:03:15

标签: java android google-maps kotlin

enter image description here我有两个编辑文本,第一个是“拾取位置”,第二个是“放下”位置。两个edittext都有latlong current和drop位置。我已经实现了onCameraIdelListeners()来拖动地图,并在Camera Target位置获取latlong。但是,当我单击第一个编辑文本时,它会根据地图标记替换地址文本,当我单击第二个编辑文本时,它在两个文本上都设置了相同的地址,但第二个地址应该不同。每当我单击任何编辑文本时,它都会设置相同的地址,而不会移动其他不同的地址。

  private fun configureCameraIdle() {
    onCameraIdleListener = GoogleMap.OnCameraIdleListener {
        mAddressList = geoCoder?.getFromLocation(mMap?.cameraPosition?.target?.latitude
                ?: 0.0, mMap?.cameraPosition?.target?.longitude
                ?: 0.0, 1) as ArrayList<Address>?; // Here 1 represent max location result to returned, by documents it recommended 1 to 5

        var icon: Int? = 0
        if (isPicClicked == false) {
            icon = R.drawable.ic_pin_red
            if (mAddressList?.size ?: 0 > 0)
                edtDropLoc?.text = mAddressList?.get(0)?.getAddressLine(0)
            currentLat = mMap?.cameraPosition?.target?.latitude
            currentLong = mMap?.cameraPosition?.target?.longitude
        } else {
            icon = R.drawable.ic_pin_green
            if (mAddressList?.size ?: 0 > 0)
                edtPicLoc?.text = mAddressList?.get(0)?.getAddressLine(0)
            dropLat = mMap?.cameraPosition?.target?.latitude
            droptLong = mMap?.cameraPosition?.target?.longitude
        }
        moveMapCameraToLocation(mMap?.cameraPosition?.target?.latitude, mMap?.cameraPosition?.target?.longitude, icon)
    }
}
 edtPicLoc?.setOnClickListener{
            isPicClicked = true
            layoutGreenPin?.visibility = View.VISIBLE
            layoutRedPin?.visibility = View.GONE
            moveMapCameraToLocation(currentLat, currentLong, R.drawable.ic_pin_green)
            Handler().postDelayed({ isDoubleClickPicLoc = false }, 2000)
        }

0 个答案:

没有答案