質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Google Cloud Platform

Google Cloud Platformは、Google社がクラウド上で提供しているサービス郡の総称です。エンドユーザー向けサービスと同様のインフラストラクチャーで運営されており、Webサイト開発から複雑なアプリ開発まで対応可能です。

Google API

Googleは多種多様なAPIを提供していて、その多くはウェブ開発者向けのAPIです。それらのAPIは消費者に人気なGoogleのサービス(Google Maps, Google Earth, AdSense, Adwords, Google Apps,YouTube等)に基づいています。

Android Studio

Android Studioは、 Google社によって開発された、 Androidのネイティブアプリケーション開発に特化した統合開発ツールです。

Kotlin

Kotlinは、ジェットブレインズ社のアンドリー・ブレスラフ、ドミトリー・ジェメロフが開発した、 静的型付けのオブジェクト指向プログラミング言語です。

Q&A

解決済

1回答

812閲覧

Android StudioでgoogleAPIを使用しマップを表示させたいですが、エラーが出ていないのに表示されません。

f25gm

総合スコア5

Google Cloud Platform

Google Cloud Platformは、Google社がクラウド上で提供しているサービス郡の総称です。エンドユーザー向けサービスと同様のインフラストラクチャーで運営されており、Webサイト開発から複雑なアプリ開発まで対応可能です。

Google API

Googleは多種多様なAPIを提供していて、その多くはウェブ開発者向けのAPIです。それらのAPIは消費者に人気なGoogleのサービス(Google Maps, Google Earth, AdSense, Adwords, Google Apps,YouTube等)に基づいています。

Android Studio

Android Studioは、 Google社によって開発された、 Androidのネイティブアプリケーション開発に特化した統合開発ツールです。

Kotlin

Kotlinは、ジェットブレインズ社のアンドリー・ブレスラフ、ドミトリー・ジェメロフが開発した、 静的型付けのオブジェクト指向プログラミング言語です。

0グッド

0クリップ

投稿2022/10/18 04:43

前提

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>

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

記述方法は間違っていなかった。
API取得の際に
有効な API に Maps SDK for Android を入れていなかった。
有効にしたら表示された。
よかった!

投稿2022/10/18 06:19

f25gm

総合スコア5

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問