【问题标题】:How to set Android Google Maps to show whole (part) world map once?如何设置 Android 谷歌地图一次显示整个(部分)世界地图?
【发布时间】:2020-07-10 07:36:58
【问题描述】:

我正在尝试在 android TV (API 29) 上显示一张全球地图 最后在app:liteMode="true" 的帮助下能够看到整个地图my tv look (img)

  1. 能否请您帮我设置一下,以便只看到绿色的矩形区域(或多一点,不重复)?
  2. 是否可以删除红色区域的按钮?原因是模式app:liteMode="true"

MainActivity.kt

import android.app.Activity
import android.os.Bundle
import android.widget.Toast
import com.google.android.gms.maps.CameraUpdateFactory
import com.google.android.gms.maps.GoogleMap
import com.google.android.gms.maps.MapsInitializer
import com.google.android.gms.maps.model.LatLng
import com.google.android.gms.maps.model.LatLngBounds
import com.google.android.gms.maps.model.MarkerOptions
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : Activity() {
    private lateinit var mMap: GoogleMap
    private val center = LatLng(.0, .0)
    private val mine = LatLngBounds(
        LatLng(-30.0,150.0), LatLng(30.0, -150.0)
    )
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        with(mapView) {
            // Initialise the MapView
            onCreate(null)
            // Set the map ready callback to receive the GoogleMap object
            getMapAsync{
                MapsInitializer.initialize(applicationContext)
                setMapLocation(it)
            }
        }
    }

    private fun setMapLocation(map : GoogleMap) {
        with(map) {
            moveCamera(CameraUpdateFactory.newLatLngZoom(center, 1f))
            addMarker(MarkerOptions().position(center))
            mapType = GoogleMap.MAP_TYPE_NORMAL
            setOnMapClickListener {
                Toast.makeText(this@MainActivity, "Clicked on map", Toast.LENGTH_SHORT).show()
            }
        }
    }

    override fun onResume() {
        super.onResume()
        mapView.onResume()
    }

    override fun onPause() {
        super.onPause()
        mapView.onPause()
    }

    override fun onDestroy() {
        super.onDestroy()
        mapView.onDestroy()
    }

    override fun onLowMemory() {
        super.onLowMemory()
        mapView.onLowMemory()
    }
}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <com.google.android.gms.maps.MapView
        android:id="@+id/mapView"
        android:layout_width="match_parent"
        android:layout_height="460dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:liteMode="true" />
</androidx.constraintlayout.widget.ConstraintLayout>

【问题讨论】:

    标签: android google-maps kotlin android-mapview android-tv


    【解决方案1】:

    检查一下以删除红色区域按钮:

    @Override
    public void onMapReady(GoogleMap googleMap) {
        googleMap.getUiSettings().setMapToolbarEnabled(false);
    
        // Do other staff
    }
    

    另外,检查这个答案 -> https://stackoverflow.com/a/46059720/8399393

    希望对你有用:)

    【讨论】:

    • 谢谢@hamidkeyhani! btns 被删除,但定位不起作用。我已经看到了那个解决方案。例如private val pointFrom = LatLng(-65.0, -180.0) // green private val pointTo = LatLng(80.0, 179.0) //blue private val mine = LatLngBounds(pointFrom, pointTo) moveCamera(CameraUpdateFactory.newLatLngZoom(mine.center, 1f))ibb.co/kHvPpCz
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-03
    • 2010-10-28
    相关资源
    最近更新 更多