Merge branch 'master' into CreateUi
This commit is contained in:
commit
312dbac710
|
@ -36,7 +36,7 @@ android {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
implementation 'com.google.maps:google-maps-services:0.15.0'
|
||||||
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'
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<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
|
<application
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
|
@ -67,3 +70,4 @@
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|
||||||
|
|
27
app/src/main/java/com/example/oplogy/AddressConverter.java
Normal file
27
app/src/main/java/com/example/oplogy/AddressConverter.java
Normal 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;
|
||||||
|
// }
|
||||||
|
//}
|
|
@ -4,13 +4,11 @@ import android.util.Log;
|
||||||
|
|
||||||
import com.google.android.gms.tasks.OnCompleteListener;
|
import com.google.android.gms.tasks.OnCompleteListener;
|
||||||
import com.google.android.gms.tasks.Task;
|
import com.google.android.gms.tasks.Task;
|
||||||
import com.google.firebase.Timestamp;
|
|
||||||
import com.google.firebase.firestore.CollectionReference;
|
import com.google.firebase.firestore.CollectionReference;
|
||||||
import com.google.firebase.firestore.FirebaseFirestore;
|
import com.google.firebase.firestore.FirebaseFirestore;
|
||||||
import com.google.firebase.firestore.QueryDocumentSnapshot;
|
import com.google.firebase.firestore.QueryDocumentSnapshot;
|
||||||
import com.google.firebase.firestore.QuerySnapshot;
|
import com.google.firebase.firestore.QuerySnapshot;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class FirestoreReception {
|
public class FirestoreReception {
|
||||||
|
@ -22,7 +20,7 @@ public class FirestoreReception {
|
||||||
}
|
}
|
||||||
|
|
||||||
//ClassIdを引数にデータの作成を行う
|
//ClassIdを引数にデータの作成を行う
|
||||||
public void getDocumentsByClassId(int classId) {
|
public void getDocumentsByClassId(int classId, MainActivity context) {
|
||||||
CollectionReference collectionRef = db.collection("QuestionnaireForms");
|
CollectionReference collectionRef = db.collection("QuestionnaireForms");
|
||||||
|
|
||||||
// classIdが引数のものを取得する
|
// classIdが引数のものを取得する
|
||||||
|
@ -35,27 +33,9 @@ public class FirestoreReception {
|
||||||
for (QueryDocumentSnapshot document : task.getResult()) {
|
for (QueryDocumentSnapshot document : task.getResult()) {
|
||||||
Map<String, Object> data = document.getData();
|
Map<String, Object> data = document.getData();
|
||||||
|
|
||||||
// デバッグ用のログ出力
|
// CreateRootクラスのインスタンスを作成し、dataを引数として渡す
|
||||||
Log.d("FirestoreReception", "Document ID: " + document.getId());
|
GeoCoder geoCoder = new GeoCoder();
|
||||||
Log.d("FirestoreReception", "Data: " + data);
|
geoCoder.processData(data, context);
|
||||||
|
|
||||||
// ここでデータを取得し、必要に応じて処理を行います
|
|
||||||
// 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);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.w("FirestoreReception", "Error getting documents.", task.getException());
|
Log.w("FirestoreReception", "Error getting documents.", task.getException());
|
||||||
|
|
59
app/src/main/java/com/example/oplogy/GeoCoder.java
Normal file
59
app/src/main/java/com/example/oplogy/GeoCoder.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,8 +1,5 @@
|
||||||
package com.example.oplogy;
|
package com.example.oplogy;
|
||||||
|
|
||||||
import androidx.appcompat.app.AlertDialog;
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
|
||||||
|
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
@ -12,6 +9,9 @@ import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
import com.google.firebase.firestore.FirebaseFirestore;
|
import com.google.firebase.firestore.FirebaseFirestore;
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
|
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
|
||||||
|
@ -65,7 +65,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
||||||
db = FirebaseFirestore.getInstance();
|
db = FirebaseFirestore.getInstance();
|
||||||
firestoreReception = new FirestoreReception();
|
firestoreReception = new FirestoreReception();
|
||||||
|
|
||||||
firestoreReception.getDocumentsByClassId(100);
|
firestoreReception.getDocumentsByClassId(100,MainActivity.this);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
buildscript {
|
buildscript {
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.google.gms:google-services:4.3.14'
|
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.
|
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||||
plugins {
|
plugins {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user