Merge branch 'master' into CreateUi

This commit is contained in:
ユタ氏 2024-06-14 12:50:38 +09:00 committed by GitHub
commit 312dbac710
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 103 additions and 32 deletions

View File

@ -36,7 +36,7 @@ android {
}
dependencies {
implementation 'com.google.maps:google-maps-services:0.15.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'

View File

@ -1,6 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" >
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
@ -66,4 +69,5 @@
</activity>
</application>
</manifest>
</manifest>

View File

@ -0,0 +1,27 @@
//package com.example.oplogy;
//import com.google.maps.GeoApiContext;
//import com.google.maps.GeocodingApi;
//import com.google.maps.model.GeocodingResult;
//import com.google.type.LatLng;
//
//
//public class AddressConverter {
// public static LatLng convertAddressToLatLng(String address) {
// try {
// // Google MapsのAPIキーを使用してGeoApiContextオブジェクトを作成します
// GeoApiContext context = new GeoApiContext.Builder()
// .apiKey("AIzaSyBQ1Ak-I2NL5TP4K59ZI0VgzKk6HNZuusw") //GoogleMapsAPiのAPiキー
// .build();
// // GeocodingApiを使用して住所を緯度経度に変換します
// GeocodingResult[] results = GeocodingApi.geocode(context, address).await();
// if (results != null && results.length > 0) {
// // 位置情報緯度と経度を返します
// return results[0].geometry.location;
// }
// } catch (Exception e) {
// e.printStackTrace();
// }
// // 結果が存在しない場合やエラーが発生した場合はnullを返します
// return null;
// }
//}

View File

@ -4,13 +4,11 @@ import android.util.Log;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.Timestamp;
import com.google.firebase.firestore.CollectionReference;
import com.google.firebase.firestore.FirebaseFirestore;
import com.google.firebase.firestore.QueryDocumentSnapshot;
import com.google.firebase.firestore.QuerySnapshot;
import java.util.List;
import java.util.Map;
public class FirestoreReception {
@ -22,7 +20,7 @@ public class FirestoreReception {
}
//ClassIdを引数にデータの作成を行う
public void getDocumentsByClassId(int classId) {
public void getDocumentsByClassId(int classId, MainActivity context) {
CollectionReference collectionRef = db.collection("QuestionnaireForms");
// classIdが引数のものを取得する
@ -35,27 +33,9 @@ public class FirestoreReception {
for (QueryDocumentSnapshot document : task.getResult()) {
Map<String, Object> data = document.getData();
// デバッグ用のログ出力
Log.d("FirestoreReception", "Document ID: " + document.getId());
Log.d("FirestoreReception", "Data: " + data);
// ここでデータを取得し必要に応じて処理を行います
// String parentName = (String) data.get("patronName");
// String childName = (String) data.get("childName");
// String studentId = (String) data.get("studentNumber");
//// Timestamp address = (Timestamp) data.get("address");
// List<Timestamp> firstDay = (List<Timestamp>) data.get("firstDay");
// List<Timestamp> secondDay = (List<Timestamp>) data.get("secondDay");
// List<Timestamp> thirdDay = (List<Timestamp>) data.get("thirdDay");
//
// // 取得したデータを使って必要な処理を行う
// Log.d("FirestoreReception", "ParentName: " + parentName);
// Log.d("FirestoreReception", "ChildName: " + childName);
// Log.d("FirestoreReception", "StudentNumber: " + studentId);
//// Log.d("FirestoreReception", "Address: " + address.toDate());
// Log.d("FirestoreReception", "First Day: " + firstDay);
// Log.d("FirestoreReception", "Second Day: " + secondDay);
// Log.d("FirestoreReception", "Third Day: " + thirdDay);
// CreateRootクラスのインスタンスを作成しdataを引数として渡す
GeoCoder geoCoder = new GeoCoder();
geoCoder.processData(data, context);
}
} else {
Log.w("FirestoreReception", "Error getting documents.", task.getException());

View File

@ -0,0 +1,59 @@
package com.example.oplogy;
import android.content.Context;
import android.location.Address;
import android.location.Geocoder;
import android.util.Log;
import com.google.android.gms.maps.model.LatLng;
import com.google.firebase.Timestamp;
import java.io.IOException;
import java.util.List;
import java.util.Locale;
import java.util.Map;
public class GeoCoder {
private Context context;
public void processData(Map<String, Object> data, Context context) {
try {
this.context = context;
//家庭訪問先の住所
List<String> address = (List<String>) data.get("address");
//家庭訪問の第一希望日(配列0が希望時間帯のはじめ配列1がおわり)
List<Timestamp> firstDay = (List<Timestamp>) data.get("firstDay");
//出席番号
Long studentNumber = (Long) data.get("studentNumber");
// 住所を緯度経度に変換
LatLng latLng = geocodeAddress(address.get(0));
Log.d("FirestoreReception", "address: " + address.get(0));
Log.d("FirestoreReception", "firstDay: " + firstDay.get(0));
Log.d("FirestoreReception", "firstDay: " + firstDay.get(1));
Log.d("FirestoreReception", "studentNumber: " + studentNumber);
// 緯度経度をLogに出力
Log.d("緯度経度", "latLng: "+latLng );
} catch (NullPointerException e) {
Log.e("NullPointerException", "getの中身がnull" + e);
}
}
private LatLng geocodeAddress(String address) {
try {
Geocoder geocoder = new Geocoder(context, Locale.getDefault());
List<Address> addresses = geocoder.getFromLocationName(address, 1);
if (addresses != null && !addresses.isEmpty()) {
Address addressResult = addresses.get(0);
double latitude = addressResult.getLatitude();
double longitude = addressResult.getLongitude();
return new LatLng(latitude, longitude);
}
} catch (IOException e) {
Log.e("GeocodingException", "Error geocoding address: " + address, e);
}
return null;
}
}

View File

@ -1,8 +1,5 @@
package com.example.oplogy;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
@ -12,6 +9,9 @@ import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import com.google.firebase.firestore.FirebaseFirestore;
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
@ -65,7 +65,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
db = FirebaseFirestore.getInstance();
firestoreReception = new FirestoreReception();
firestoreReception.getDocumentsByClassId(100);
firestoreReception.getDocumentsByClassId(100,MainActivity.this);

View File

@ -1,10 +1,11 @@
buildscript {
dependencies {
classpath 'com.google.gms:google-services:4.3.14'
}
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' 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
}
}