Merge pull request #2 from N-YOKU-jp/Googlemapinstall

Googlemapinstall
This commit is contained in:
ユタ氏 2024-06-05 14:20:49 +09:00 committed by GitHub
commit e86a1789b9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 112 additions and 14 deletions

View File

@ -1,15 +1,16 @@
plugins { plugins {
id 'com.android.application' id 'com.android.application'
id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin'
} }
android { android {
namespace 'com.example.oplogy' namespace 'com.example.oplogy'
compileSdk 33 compileSdk 34
defaultConfig { defaultConfig {
applicationId "com.example.oplogy" applicationId "com.example.oplogy"
minSdk 26 minSdk 26
targetSdk 33 targetSdk 34
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"
@ -26,6 +27,9 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8 sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8
} }
buildFeatures {
viewBinding true
}
} }
dependencies { dependencies {
@ -33,6 +37,7 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.6.1' implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.5.0' implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4' implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'com.google.android.gms:play-services-maps:18.2.0'
testImplementation 'junit:junit:4.13.2' testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5' androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'

View File

@ -12,6 +12,33 @@
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/Theme.Oplogy" android:theme="@style/Theme.Oplogy"
tools:targetApi="31"> tools:targetApi="31">
<!--
TODO: Before you run your application, you need a Google Maps API key.
To get one, follow the directions here:
https://developers.google.com/maps/documentation/android-sdk/get-api-key
Once you have your API key (it starts with "AIza"), define a new property in your
project's local.properties file (e.g. MAPS_API_KEY=Aiza...), and replace the
"YOUR_API_KEY" string in this file with "${MAPS_API_KEY}".
-->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value = "AIzaSyBQ1Ak-I2NL5TP4K59ZI0VgzKk6HNZuusw" />
<activity
android:name=".MapsActivity"
android:exported="true"
android:label="@string/title_activity_maps">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity <activity
android:name=".MainActivity" android:name=".MainActivity"
android:exported="true"> android:exported="true">

View File

@ -20,19 +20,18 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
button = findViewById(R.id.button1);
button.setOnClickListener(this);
editText = findViewById(R.id.textview1); findViewById(R.id.mapmapcreate).setOnClickListener(
view->{
} }
);
}
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if (v == button){
editText.setText("押した");
}
} }
} }

View File

@ -0,0 +1,56 @@
package com.example.oplogy;
import androidx.fragment.app.FragmentActivity;
import android.os.Bundle;
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.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.example.oplogy.databinding.ActivityMapsBinding;
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
private ActivityMapsBinding binding;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityMapsBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
/**
* 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
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in Sydney and move the camera
/// 緯度経度
LatLng loc = new LatLng(35.17260398479137, 136.88635173557998);
/// マーカーオプションを設定情報ウィンドウ
mMap.addMarker(new MarkerOptions().position(loc).title("トライデントコンピュータ専門学校"));
/// 表示位置を地図に指定
mMap.moveCamera(CameraUpdateFactory.newLatLng(loc));
/// 地図の倍率を指定
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(loc, 17));
}
}

View File

@ -8,8 +8,8 @@
android:orientation="vertical"> android:orientation="vertical">
<Button <Button
android:id="@+id/button1" android:id="@+id/mapmapcreate"
android:text="押せよ" android:text="マップ生成"
android:textSize="50px" android:textSize="50px"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MapsActivity" />

View File

@ -1,3 +1,4 @@
<resources> <resources>
<string name="app_name">oplogy</string> <string name="app_name">oplogy</string>
<string name="title_activity_maps">MapsActivity</string>
</resources> </resources>

View File

@ -2,4 +2,5 @@
plugins { plugins {
id 'com.android.application' version '8.0.2' apply false id 'com.android.application' version '8.0.2' apply false
id 'com.android.library' version '8.0.2' apply false id 'com.android.library' version '8.0.2' apply false
id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin' version '2.0.1' apply false
} }