【发布时间】:2018-07-22 06:45:37
【问题描述】:
我想从地图中心获取坐标并在 textview 中显示坐标,当我滚动地图时,textview 中的坐标会发生变化。此代码不起作用,虽然我滚动地图,但 textview 仅显示我当前位置的坐标。
我的 Kotlin 代码:
class ActivityMaps :
AppCompatActivity(),
OnMapReadyCallback,
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener,
LocationListener{
...
override fun onLocationChanged(newLocation: Location?) {
val latLng = LatLng(newLocation!!.latitude, newLocation.longitude)
mMaps!!.moveCamera(CameraUpdateFactory.newLatLng(latLng))
mMaps!!.animateCamera(CameraUpdateFactory.zoomTo(18f))
if (mGoogleApiClient != null){
LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this)
}
mMaps.setOnCameraIdleListener(GoogleMap.OnCameraIdleListener() {
val centerPos : LatLng = mMapsNPlotBng.cameraPosition.target
tv_latitute!!.text = centerPos.latitude.toString()
tv_longitude!!.text = centerPos.longitude.toString()
})
}
...
}
请帮助我,谢谢。
【问题讨论】:
-
您希望您的文本视图始终位于地图中心吗?意味着即使地图移动,文本视图也应该保持在地图的中心?
标签: android google-maps kotlin