myDataListのAddress(住所)をlatlng(緯度経度)に変換する処理の実装 #25
|
@ -1,17 +1,23 @@
|
||||||
package com.example.oplogy;
|
package com.example.oplogy;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.location.Address;
|
||||||
|
import android.location.Geocoder;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.room.Room;
|
import androidx.room.Room;
|
||||||
|
|
||||||
|
import com.google.android.gms.maps.model.LatLng;
|
||||||
import com.google.firebase.Timestamp;
|
import com.google.firebase.Timestamp;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
@ -32,8 +38,10 @@ public class CreateRoot {
|
||||||
|
|
||||||
private final AppDatabase db;
|
private final AppDatabase db;
|
||||||
private int arraySize;
|
private int arraySize;
|
||||||
|
boolean Duplicates=true;
|
||||||
|
boolean secondDuplicates=true;
|
||||||
|
|
||||||
boolean secondDuplicates;
|
private Context context;
|
||||||
|
|
||||||
String testdata[] = {"20240604", "20240605", "20240606"};
|
String testdata[] = {"20240604", "20240605", "20240606"};
|
||||||
|
|
||||||
|
@ -83,12 +91,12 @@ public class CreateRoot {
|
||||||
|
|
||||||
outPutLogIntervalArray(intervalArray);
|
outPutLogIntervalArray(intervalArray);
|
||||||
//スケジュール作成
|
//スケジュール作成
|
||||||
boolean Duplicates = createSchedule(myDataList, intervalArray);
|
Duplicates = createSchedule(myDataList, intervalArray);
|
||||||
|
|
||||||
//重複によるエラー確認
|
//重複によるエラー確認
|
||||||
if (!Duplicates) {
|
if (!Duplicates) {
|
||||||
sortSchedule(myDataList);
|
sortSchedule(myDataList);
|
||||||
outPutLogSchedule(myDataList);
|
|
||||||
} else {
|
} else {
|
||||||
//第二希望日で同じ処理を行う
|
//第二希望日で同じ処理を行う
|
||||||
Log.d("CreateRoot", "第二希望");
|
Log.d("CreateRoot", "第二希望");
|
||||||
|
@ -97,13 +105,16 @@ public class CreateRoot {
|
||||||
secondDuplicates = secondCreateSchedule(myDataList, intervalArray);
|
secondDuplicates = secondCreateSchedule(myDataList, intervalArray);
|
||||||
if (!secondDuplicates) {
|
if (!secondDuplicates) {
|
||||||
sortSchedule(myDataList);
|
sortSchedule(myDataList);
|
||||||
outPutLogSchedule(myDataList);
|
|
||||||
} else {
|
} else {
|
||||||
Log.d("CreateRoot", "重複によるエラー");
|
Log.d("CreateRoot", "重複によるエラー");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!secondDuplicates) {
|
if (!secondDuplicates) {
|
||||||
|
geocodeAddress(myDataList);
|
||||||
|
outPutLogSchedule(myDataList);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
@ -346,12 +357,30 @@ public class CreateRoot {
|
||||||
myDataList.sort(comparator);
|
myDataList.sort(comparator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private void geocodeAddress(List<MyDataClass> myDataList) {
|
||||||
|
try {
|
||||||
|
Geocoder geocoder = new Geocoder(context, Locale.getDefault());
|
||||||
|
for(int i=0;i<myDataList.size();i++) {
|
||||||
|
List<Address> addresses = geocoder.getFromLocationName(myDataList.get(i).getAddress().toString(), 1);
|
||||||
|
if (addresses != null && !addresses.isEmpty()) {
|
||||||
|
Address addressResult = addresses.get(0);
|
||||||
|
double latitude = addressResult.getLatitude();
|
||||||
|
double longitude = addressResult.getLongitude();
|
||||||
|
myDataList.get(i).setLatLng(new LatLng(latitude, longitude));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
Log.e("CreateRoot", "緯度経度の取得に失敗: " +e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void outPutLogSchedule(List<MyDataClass> myDataList) {
|
private void outPutLogSchedule(List<MyDataClass> myDataList) {
|
||||||
for (int i = 0; i < myDataList.size(); i++) {
|
for (int i = 0; i < myDataList.size(); i++) {
|
||||||
Log.d("CreateRoot:outPutLogSchedule", "(index: " + i + ") data: " + myDataList.get(i));
|
Log.d("CreateRoot:outPutLogSchedule", "(index: " + i + ") data: " + myDataList.get(i));
|
||||||
Log.d("CreateRoot:outPutLogSchedule", "(index: " + i + ") Schedule: " + myDataList.get(i).getSchedule());
|
Log.d("CreateRoot:outPutLogSchedule", "(index: " + i + ") Schedule: " + myDataList.get(i).getSchedule());
|
||||||
Log.d("CreateRoot:outPutLogSchedule", "(index: " + i + ") date: " + myDataList.get(i).getStartDateString());
|
Log.d("CreateRoot","(index: " + i + ") LatLng"+myDataList.get(i).getLatLng());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -270,12 +270,6 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
||||||
.setTitle("警告")
|
.setTitle("警告")
|
||||||
.setMessage(message.toString())
|
.setMessage(message.toString())
|
||||||
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
|
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
latch.countDown();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
package com.example.oplogy;
|
package com.example.oplogy;
|
||||||
|
|
||||||
|
import com.google.android.gms.maps.model.LatLng;
|
||||||
import com.google.firebase.Timestamp;
|
import com.google.firebase.Timestamp;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class MyDataClass {
|
public class MyDataClass {
|
||||||
|
|
||||||
String patronName;
|
String patronName;
|
||||||
int classId;
|
int classId;
|
||||||
List<String> address;
|
List<String> address;
|
||||||
|
@ -28,6 +30,7 @@ public class MyDataClass {
|
||||||
private Long secondDayTimezone;
|
private Long secondDayTimezone;
|
||||||
private String secondDayParentStartTimeString;
|
private String secondDayParentStartTimeString;
|
||||||
private String secondDayParentEndTimeString;
|
private String secondDayParentEndTimeString;
|
||||||
|
private LatLng latLng;
|
||||||
|
|
||||||
|
|
||||||
public MyDataClass(String patronName, int classId, List<String> address, List<Timestamp> firstDay, int studentNumber, String childName, List<Timestamp> thirdDay, List<Timestamp> secondDay) {
|
public MyDataClass(String patronName, int classId, List<String> address, List<Timestamp> firstDay, int studentNumber, String childName, List<Timestamp> thirdDay, List<Timestamp> secondDay) {
|
||||||
|
@ -235,4 +238,12 @@ public class MyDataClass {
|
||||||
public String getSecondDayStartDateString() {
|
public String getSecondDayStartDateString() {
|
||||||
return secondDayStartDateString;
|
return secondDayStartDateString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setLatLng(LatLng latLng) {
|
||||||
|
this.latLng=latLng;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LatLng getLatLng() {
|
||||||
|
return latLng;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user