diff --git a/app/src/main/java/com/example/cosmosclient/GPSresources/StoreLocations.java b/app/src/main/java/com/example/cosmosclient/GPSresources/StoreLocations.java deleted file mode 100644 index c5ac65f..0000000 --- a/app/src/main/java/com/example/cosmosclient/GPSresources/StoreLocations.java +++ /dev/null @@ -1,87 +0,0 @@ -package com.example.cosmosclient.GPSresources; - -import android.location.Location; - -import com.example.cosmosclient.entities.Feature; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; - -public class StoreLocations { - private double NowLat; - private double NowLon; - private HashMap> feature = new HashMap<>(); - /*戻り値となる通知が必要なお店情報を格納する連想配列を作成*/ - private ArrayList nearShops=new ArrayList<>(); - - public StoreLocations(double NowLat, double NowLon){ - this.NowLat=NowLat; - this.NowLon=NowLon; - } - public void updateLocations(double NowLat,double NowLon){ - this.NowLat=NowLat; - this.NowLon=NowLon; - } - public double getNowLat(){ - return this.NowLat; - } - public double getNowLon(){ - return this.NowLon; - } - - public void setNearShops(HashMap> feature){ - this.feature=feature; - //Hashmapを順番に実行 - for(HashMap.Entry> e : feature.entrySet()) { - //ArrayList>を回していく - for(int i=0; i < e.getValue().size();i++) { - float[] distance = getDistance(this.NowLat, this.NowLon, e.getValue().get(i).getLocation().getLatitude(), e.getValue().get(i).getLocation().getLongitude()); - // distance[0] = [2点間の距離] - if (distance[0] <= 50) { - /*ここから通知に必要な近い店の情報を格納する処理を記述*/ - /*中身を作成*/ - Feature chilldFeature = new Feature(); - chilldFeature.setCode(e.getValue().get(i).getCode()); - chilldFeature.setLocation(e.getValue().get(i).getLocation()); - chilldFeature.setName(e.getValue().get(i).getName()); - if(nearShops.indexOf(chilldFeature)!=-1){ - /*通知に必要な近い店の情報を格納する処理を格納*/ - nearShops.add(chilldFeature); - } - } - } - } - } - public ArrayList getNearShops() { - return nearShops; - } - - /*通知送信後、通知すべきショップ情報リストから削除する*/ - /*引数はArrayList型*/ - /*引数のArrayListと一致するものをnearShopsから削除する*/ - public void deleteNearShops(ArrayList deleteList) { - for(int i=0; i < deleteList.size();i++){ - if(nearShops.indexOf(deleteList)!=-1){ - /*ここで削除*/ - nearShops.remove(nearShops.indexOf(deleteList)); - } - - } - - } - - - public float[] getDistance(double x, double y, double x2, double y2) { - // 結果を格納するための配列を生成 - float[] results = new float[3]; - // results[0] = [2点間の距離] - // results[1] = [始点から見た方位角] - // results[2] = [終点から見た方位角] - - // 距離計算 - Location.distanceBetween(x, y, x2, y2, results); - - return results; - } -} diff --git a/app/src/main/java/com/example/cosmosclient/GPSresources/StoreLocationsMethods.java b/app/src/main/java/com/example/cosmosclient/GPSresources/StoreLocationsMethods.java new file mode 100644 index 0000000..438a058 --- /dev/null +++ b/app/src/main/java/com/example/cosmosclient/GPSresources/StoreLocationsMethods.java @@ -0,0 +1,88 @@ +package com.example.cosmosclient.GPSresources; + +import android.location.Location; + +import com.example.cosmosclient.entities.Feature; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +public class StoreLocationsMethods { + private double NowLat; + private double NowLon; + private HashMap> feature = new HashMap<>(); + /*戻り値となる通知が必要なお店情報を格納する連想配列を作成*/ + private ArrayList nearShops=new ArrayList<>(); + + public StoreLocationsMethods(double NowLat, double NowLon){ + this.NowLat=NowLat; + this.NowLon=NowLon; + } + public void updateLocations(double NowLat,double NowLon){ + this.NowLat=NowLat; + this.NowLon=NowLon; + } + public double getNowLat(){ + return this.NowLat; + } + public double getNowLon(){ + return this.NowLon; + } + + public void setNearShops(HashMap> feature){ + this.feature=feature; + //Hashmapを順番に実行 + for(HashMap.Entry> e : feature.entrySet()) { + //ArrayList>を回していく + for(int i=0; i < e.getValue().size();i++) { + float[] distance = getDistance(this.NowLat, this.NowLon, e.getValue().get(i).getLocation().getLatitude(), e.getValue().get(i).getLocation().getLongitude()); + // distance[0] = [2点間の距離] + //m単位 + if (distance[0] <= 50) { + /*ここから通知に必要な近い店の情報を格納する処理を記述*/ + /*中身を作成*/ + Feature childFeature = new Feature(); + childFeature.setCode(e.getValue().get(i).getCode()); + childFeature.setLocation(e.getValue().get(i).getLocation()); + childFeature.setName(e.getValue().get(i).getName()); + if(nearShops.indexOf(childFeature)!=-1){ + /*通知に必要な近い店の情報を格納する処理を格納*/ + nearShops.add(childFeature); + } + } + } + } + } + public ArrayList getNearShops() { + return nearShops; + } + + /*通知送信後、通知すべきショップ情報リストから削除する*/ + /*引数はArrayList型*/ + /*引数のArrayListと一致するものをnearShopsから削除する*/ + public void deleteNearShops(ArrayList deleteList) { + for(int i=0; i < deleteList.size();i++){ + if(nearShops.indexOf(deleteList)!=-1){ + /*ここで削除*/ + nearShops.remove(nearShops.indexOf(deleteList)); + } + + } + + } + + + public float[] getDistance(double x, double y, double x2, double y2) { + // 結果を格納するための配列を生成 + float[] results = new float[3]; + // results[0] = [2点間の距離] + // results[1] = [始点から見た方位角] + // results[2] = [終点から見た方位角] + + // 距離計算 + Location.distanceBetween(x, y, x2, y2, results); + + return results; + } +}