【问题标题】:How to get coordinate center maps on android and showing in textview?如何在android上获取坐标中心图并在textview中显示?
【发布时间】:2018-07-16 04:00:10
【问题描述】:

我正在尝试从地图中心获取坐标并在 textview 中显示,当我滚动地图时,坐标发生了变化。

这是我的 Kotlin 代码:

class ActivityMapsNewPlotBng :
        AppCompatActivity(),
        OnMapReadyCallback,
        GoogleMap.OnCameraIdleListener,
        GoogleApiClient.ConnectionCallbacks,
        GoogleApiClient.OnConnectionFailedListener,
        LocationListener{
...
override fun onLocationChanged(newLocation: Location?) {
        val latLng = LatLng(newLocation!!.latitude, newLocation.longitude)
        mMapsNPlotBng!!.moveCamera(CameraUpdateFactory.newLatLng(latLng))
        mMapsNPlotBng!!.animateCamera(CameraUpdateFactory.zoomTo(18f))
        if (mGoogleApiClient != null){
            LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this)
        }

    }

    override fun onCameraIdle() {
        val centerPos : LatLng = mMapsNPlotBng.cameraPosition.target
        tv_nplotbng_lat.setText("" + centerPos.latitude)
        tv_nplotbng_long.setText("" + centerPos.longitude)
    }
}

此代码无效,请帮助我。 感谢关注。

【问题讨论】:

  • 显然,如果滚动,中心坐标会改变:|
  • 是的,我想在 textview 中显示该坐标。但是,我的代码不起作用

标签: android google-maps kotlin


【解决方案1】:

在 onCameraIdle 方法中

LatLng latLng = googleMap.getProjection().getVisibleRegion().latLngBounds.getCenter();

【讨论】:

  • 投影操作繁重
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-25
  • 1970-01-01
  • 2012-08-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多