前提
https://www.youtube.com/watch?v=liyzwakkzEQ
こちらの動画を見ながらAPIを使用しmapを表示させるアプリを作りたいです。
APIを生成する手順は異なっており、
プロジェクトを作った後に認証情報を作成で作りました。
また、xmlも異なっていたため以下に貼り付けておきます。
API_HEREとなっていたところに取得したAPIは貼ってます。
エラーは出ておりません。
エミュレーターでは、左下にgoogleというロゴ?は出ていますがマップは表示されていない状態です。
実現したいこと
マップを表示させる
発生している問題・エラーメッセージ
なし
該当のソースコード
MapsActivity.kt
1package com.example.googlemapapp 2 3import androidx.appcompat.app.AppCompatActivity 4import android.os.Bundle 5 6import com.google.android.gms.maps.CameraUpdateFactory 7import com.google.android.gms.maps.GoogleMap 8import com.google.android.gms.maps.OnMapReadyCallback 9import com.google.android.gms.maps.SupportMapFragment 10import com.google.android.gms.maps.model.LatLng 11import com.google.android.gms.maps.model.MarkerOptions 12import com.example.googlemapapp.databinding.ActivityMapsBinding 13 14class MapsActivity : AppCompatActivity(), OnMapReadyCallback { 15 16 private lateinit var mMap: GoogleMap 17 private lateinit var binding: ActivityMapsBinding 18 19 override fun onCreate(savedInstanceState: Bundle?) { 20 super.onCreate(savedInstanceState) 21 22 binding = ActivityMapsBinding.inflate(layoutInflater) 23 setContentView(binding.root) 24 25 // Obtain the SupportMapFragment and get notified when the map is ready to be used. 26 val mapFragment = supportFragmentManager 27 .findFragmentById(R.id.map) as SupportMapFragment 28 mapFragment.getMapAsync(this) 29 } 30 31 /** 32 * Manipulates the map once available. 33 * This callback is triggered when the map is ready to be used. 34 * This is where we can add markers or lines, add listeners or move the camera. In this case, 35 * we just add a marker near Sydney, Australia. 36 * If Google Play services is not installed on the device, the user will be prompted to install 37 * it inside the SupportMapFragment. This method will only be triggered once the user has 38 * installed Google Play services and returned to the app. 39 */ 40 override fun onMapReady(googleMap: GoogleMap) { 41 mMap = googleMap 42 43 // Add a marker in Sydney and move the camera 44// val sydney = LatLng(-34.0, 151.0) 45// mMap.addMarker(MarkerOptions().position(sydney).title("Marker in Sydney")) 46// mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney)) 47 48 49//1)京都を表示 50 val kyoto =LatLng(35.011665, 135.768326) //緯度・経度 51 mMap.addMarker(MarkerOptions().position(kyoto).title("Marker in kyoto")) 52 mMap.moveCamera(CameraUpdateFactory.newLatLng(kyoto)) 53 } 54}
AndroidManifest.xml
1<?xml version="1.0" encoding="utf-8"?> 2<manifest xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:tools="http://schemas.android.com/tools" 4 package="com.example.googlemapapp"> 5 6 <application 7 android:allowBackup="true" 8 android:dataExtractionRules="@xml/data_extraction_rules" 9 android:fullBackupContent="@xml/backup_rules" 10 android:icon="@mipmap/ic_launcher" 11 android:label="@string/app_name" 12 android:roundIcon="@mipmap/ic_launcher_round" 13 android:supportsRtl="true" 14 android:theme="@style/Theme.GoogleMapApp" 15 tools:targetApi="31"> 16 17 <!-- 18 TODO: Before you run your application, you need a Google Maps API key. 19 20 To get one, follow the directions here: 21 22 https://developers.google.com/maps/documentation/android-sdk/get-api-key 23 24 Once you have your API key (it starts with "AIza"), define a new property in your 25 project's local.properties file (e.g. MAPS_API_KEY=Aiza...), and replace the 26 "YOUR_API_KEY" string in this file with "${MAPS_API_KEY}". 27 --> 28 <meta-data 29 android:name="com.google.android.geo.API_KEY" 30 android:value="ここにAPIを記載しました" /> 31 32 <activity 33 android:name=".MapsActivity" 34 android:exported="true" 35 android:label="@string/title_activity_maps"> 36 <intent-filter> 37 <action android:name="android.intent.action.MAIN" /> 38 39 <category android:name="android.intent.category.LAUNCHER" /> 40 </intent-filter> 41 </activity> 42 </application> 43 44</manifest>

回答1件
あなたの回答
tips
プレビュー
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。
また依頼した内容が修正された場合は、修正依頼を取り消すようにしましょう。