Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Kotlin谷歌地图没有启动_Android_Google Maps_Kotlin - Fatal编程技术网

Android Kotlin谷歌地图没有启动

Android Kotlin谷歌地图没有启动,android,google-maps,kotlin,Android,Google Maps,Kotlin,在那里设置permıssıon代码,因为我想检查程序是否在那里运行,程序是否从未在那里运行过,并且希望permısessionı也尝试了Toast,但程序从未打开过它 映射片段的主要活动的Xml lass MapsActivity : AppCompatActivity(), OnMapReadyCallback { private lateinit var mMap: GoogleMap override fun onCreate(savedInstanceState: B

在那里设置permıssıon代码,因为我想检查程序是否在那里运行,程序是否从未在那里运行过,并且希望permısessionı也尝试了Toast,但程序从未打开过它

映射片段的主要活动的Xml

lass MapsActivity : AppCompatActivity(), OnMapReadyCallback {

    private lateinit var mMap: GoogleMap

    override fun onCreate(savedInstanceState: Bundle?) {

        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_maps)
        // Obtain the SupportMapFragment and get notified when the map is ready to be used.
        val mapFragment = supportFragmentManager
            .findFragmentById(R.id.map) as SupportMapFragment
        mapFragment.getMapAsync(this)
        val permissionx= arrayOf(android.Manifest.permission.ACCESS_BACKGROUND_LOCATION)
        ActivityCompat.requestPermissions(this, permissionx,0)

    }

    /**
     * Manipulates the map once available.
     * This callback is triggered when the map is ready to be used.
     * This is where we can add markers or lines, add listeners or move the camera. In this case,
     * we just add a marker near Sydney, Australia.
     * If Google Play services is not installed on the device, the user will be prompted to install
     * it inside the SupportMapFragment. This method will only be triggered once the user has
     * installed Google Play services and returned to the app.
     */
    override fun onMapReady(googleMap: GoogleMap) {
        mMap = googleMap

        // Add a marker in Sydney and move the camera
        val sydney = LatLng(-34.0, 151.0)
        mMap.addMarker(MarkerOptions().position(sydney).title("Marker in Sydney"))
        mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney))
    }
}

我确信我输入的钥匙是正确的

这是我的程序清单

<fragment
            android:id="@+id/map"
            android:name="com.google.android.gms.maps.SupportMapFragment"

            android:layout_width="match_parent"
            android:layout_height="259dp"
            tools:context="com.example.siparis.MapsActivity" />

Logcat中唯一的错误是:

2020-03-06 16:52:50.32320804-20804/?E/example.sipari:未知位 在运行时设置_标志:0x8000

请检查以下内容:

允许应用程序访问后台位置。如果您请求此权限,还必须请求访问\u粗略\u位置或访问\u精细\u位置。单独请求此权限不会授予您位置访问权限。


我认为你缺少权限。请在使用前提出请求。

您应该在
onMapReady()内调用
mMap.onResume()


任何例外??没有例外。让我用logcati进行编辑,我已经启用了permıssı,程序将不会在后台运行。请更新您的问题,因为它目前只请求访问背景位置。请注意,根据android版本,在清单中声明是不够的。尝试在onmapcreate中Toast,它甚至不会显示Toast。或者它甚至不检查permıssıon,即使我在onCreateMap中编码它也没有接口mMap.onResume()没有mMap.onResume()不没有@如果您在布局中使用的是
片段而不是
地图视图
,则奥乌兹库鲁卡亚会将您的地图投射到
SupportMapFragment
。我在所有代码中都将其用作SupportMapFragment
 <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.siparis">

    <!--
         The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
         Google Maps Android API v2, but you must specify either coarse or fine
         location permissions for the 'MyLocation' functionality.
    -->
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.AppCompat.NoActionBar">

        <!--
             The API key for Google Maps-based APIs is defined as a string resource.
             (See the file "res/values/google_maps_api.xml").
             Note that the API key is linked to the encryption key used to sign the APK.
             You need a different API key for each encryption key, including the release key that is used to
             sign the APK for publishing.
             You can define the keys for the debug and release targets in src/debug/ and src/release/.
        -->
        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="@string/google_maps_key" />

        <activity
            android:name=".MapsActivity"
            android:label="@string/title_activity_maps"></activity>
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
override fun onMapReady(googleMap: GoogleMap) {
    mMap = googleMap

    // Add a marker in Sydney and move the camera
    val sydney = LatLng(-34.0, 151.0)
    mMap.addMarker(MarkerOptions().position(sydney).title("Marker in Sydney"))
    mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney))

    //map is the mapview in the layout
    (map as SupportMapFragment).onResume() //this line is very necessary
}