diff --git a/app/src/main/java/com/example/cosmosclient/GPSresources/StoreLocationCompare.java b/app/src/main/java/com/example/cosmosclient/GPSresources/StoreLocationCompare.java new file mode 100644 index 0000000..e729a2b --- /dev/null +++ b/app/src/main/java/com/example/cosmosclient/GPSresources/StoreLocationCompare.java @@ -0,0 +1,67 @@ +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 StoreLocationCompare { + private double NowLat; + private double NowLon; + private HashMap> feature = new HashMap<>(); + /*戻り値となる通知が必要なお店情報を格納する連想配列を作成*/ + private ArrayList neaShops=new ArrayList<>(); + + public StoreLocationCompare(double NowLat,double NowLon){ + this.NowLat=NowLat; + this.NowLon=NowLon; + } + public StoreLocationCompare(double NowLat,double NowLon,HashMap> feature){ + this.NowLat=NowLat; + this.NowLon=NowLon; + this.feature=feature; + } + public double getNowLat(){ + return this.NowLat; + } + public double getNowLon(){ + return this.NowLon; + } + + public ArrayList getNeaShops(){ + //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()); + 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()); + /*通知に必要な近い店の情報を格納する処理を格納*/ + neaShops.add(chilldFeature); + } + } + } + /*ここで通知に必要な近い店の情報を返すArrayList型*/ + return neaShops; + } + 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; + } +}