我添加了 Google Map API 并添加了我的标记,但是当应用程序运行时,它被缩小了很多。我尝试研究,但找不到我需要的东西。有人可以告诉我加载地图后如何设置缩放级别吗?例如,它应该只显示一个城市而不是整个世界。
这是我的片段代码
package com.example.myassignment.Fragments
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.example.myassignment.R
import com.google.android.gms.maps.CameraUpdateFactory
import com.google.android.gms.maps.GoogleMap
import com.google.android.gms.maps.OnMapReadyCallback
import com.google.android.gms.maps.model.LatLng
import com.google.android.gms.maps.model.MarkerOptions
import kotlinx.android.synthetic.main.fragment_destinations.*
private const val ARG_PARAM1 = "param1"
private const val ARG_PARAM2 = "param2"
class DestinationsFragment : Fragment(), OnMapReadyCallback {
private var param1: String? = null
private var param2: String? = null
private lateinit var googleMap: GoogleMap
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
arguments?.let {
param1 = it.getString(ARG_PARAM1)
param2 = it.getString(ARG_PARAM2)
}
mapView.onCreate(savedInstanceState)
mapView.onResume()
mapView.getMapAsync(this)
}
override fun onMapReady(map: GoogleMap?) {
map?.let {
googleMap = it
}
val sydney = LatLng(-34.0, 151.0)
val stokeOnTrent = LatLng(53.025780,-2.177390)
val stokeCobrdige = LatLng(53.029380,-2.188740)
// Here's my markers
googleMap.addMarker(MarkerOptions().position(sydney).title("Marker in Sydney"))
googleMap.addMarker(MarkerOptions().position(stokeOnTrent).title("Stoke Center"))
googleMap.addMarker(MarkerOptions().position(stokeCobrdige).title("Cobridge - Stoke"))
googleMap.minZoomLevel
googleMap.moveCamera(CameraUpdateFactory.newLatLng(stokeOnTrent))
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_destinations, container, false)
}
companion object {
/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* @param param1 Parameter 1.
* @param param2 Parameter 2.
* @return A new instance of fragment DestinationsFragment.
*/
// TODO: Rename and change types and number of parameters
@JvmStatic
fun newInstance(param1: String, param2: String) =
DestinationsFragment().apply {
arguments = Bundle().apply {
putString(ARG_PARAM1, param1)
putString(ARG_PARAM2, param2)
}
}
}
}
谢谢!