【发布时间】:2021-05-12 21:25:28
【问题描述】:
当我打开该片段时,我在我的应用程序中实现了谷歌地图(在片段中),当我获得正确的纬度、经度时它只显示灰屏
代码
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
val root = inflater.inflate(R.layout.fragment_map_to_customer, container, false)
customerAddressArgument = requireArguments().getString("customerAddressArgument").toString()
// Google Maps
var mapView = root.findViewById(R.id.map) as MapView
mapView.getMapAsync(this)
mapView.onCreate(arguments)
return root
}
override fun onMapReady(googleMap: GoogleMap) {
mMap = googleMap
// mMap.uiSettings.isZoomControlsEnabled = true
val geoCoder = Geocoder(context)
var address = geoCoder.getFromLocationName(customerAddressArgument, 1)!![0]
val latLng = LatLng(address.latitude, address.longitude)
mMap!!.addMarker(MarkerOptions().position(latLng).title("Location"))
mMap!!.animateCamera(CameraUpdateFactory.newLatLng(latLng))
Log.d("latLng20:", latLng.toString()) <-- return: **D/latLng20:: lat/lng: (-6.3946055,106.7947916)**
Toast.makeText(
context,
address.latitude.toString() + " " + address.longitude,
Toast.LENGTH_LONG
).show()
}
latLng 在谷歌maps website
有什么想法吗?
【问题讨论】:
-
mapView.onCreate(arguments)是什么,我在文档中没有找到它? -
@PavelPoley 没有该地图将不会被加载
-
你的地图sdk启用了吗?
-
@UsamaAltaf 是的,我想是的,但要确定我应该在哪里检查它?
标签: android google-maps kotlin google-maps-android-api-2 android-maps