diff --git a/app/src/main/java/com/example/cosmosclient/GPSresources/StoreLocationsMethods.java b/app/src/main/java/com/example/cosmosclient/GPSresources/StoreLocationsMethods.java index 51c215e..dcf1453 100644 --- a/app/src/main/java/com/example/cosmosclient/GPSresources/StoreLocationsMethods.java +++ b/app/src/main/java/com/example/cosmosclient/GPSresources/StoreLocationsMethods.java @@ -45,7 +45,7 @@ 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()); + childFeature.setGenre(e.getValue().get(i).getGenre()); if(nearShops.indexOf(childFeature)==-1){ /*通知に必要な近い店の情報を格納する処理を格納*/ nearShops.add(childFeature); diff --git a/app/src/main/java/com/example/cosmosclient/app/Cosmos.java b/app/src/main/java/com/example/cosmosclient/app/Cosmos.java index ede712b..30be5e1 100644 --- a/app/src/main/java/com/example/cosmosclient/app/Cosmos.java +++ b/app/src/main/java/com/example/cosmosclient/app/Cosmos.java @@ -4,10 +4,8 @@ import com.example.cosmosclient.entities.AreaInformation; import com.example.cosmosclient.entities.Group; -import com.example.cosmosclient.entities.Location; -import java.util.HashMap; - +import java.util.ArrayList; import java.util.HashMap; public class Cosmos extends Application { @@ -16,6 +14,7 @@ private HashMap groups = new HashMap<>(); private String uId=null; private HashMap areaInfo = new HashMap<>(); + private ArrayList areaInfoKey= new ArrayList<>(); //token処理 public void setToken(String token){ @@ -64,5 +63,11 @@ public AreaInformation getAreaInfo(int areaId){ return areaInfo.get(areaId); } + public ArrayList AreaInfoGetKey(){ + for(int key : areaInfo.keySet()){ + areaInfoKey.add(key); + } + return areaInfoKey; + } } diff --git a/app/src/main/java/com/example/cosmosclient/entities/AreaInformation.java b/app/src/main/java/com/example/cosmosclient/entities/AreaInformation.java index 4a581ac..8149215 100644 --- a/app/src/main/java/com/example/cosmosclient/entities/AreaInformation.java +++ b/app/src/main/java/com/example/cosmosclient/entities/AreaInformation.java @@ -5,14 +5,25 @@ import java.util.HashMap; public class AreaInformation { - private Location location = new Location(); + private CosmosLocation location = new CosmosLocation(); + //private ArrayList shops = new ArrayList<>(); private HashMap> feature = new HashMap<>(); private Time lastUpdated; + private double latitude; + private double longitude; - public void setLocation(Location location){ + public void setLatitude(double latitude) { + location.setLatitude(latitude); + } + + public void setLongitude(double longitude) { + location.setLongitude(longitude); + } + + public void setLocation(CosmosLocation location){ this.location = location; } - public Location getLocation(){ + public CosmosLocation getLocation(){ return this.location; } @@ -29,4 +40,11 @@ public Time getLastUpdated() { return lastUpdated; } + +// public void setShops(ArrayList shops) { +// this.shops = shops; +// } +// public ArrayList getShops() { +// return shops; +// } } diff --git a/app/src/main/java/com/example/cosmosclient/entities/CosmosLocation.java b/app/src/main/java/com/example/cosmosclient/entities/CosmosLocation.java new file mode 100644 index 0000000..a13d9db --- /dev/null +++ b/app/src/main/java/com/example/cosmosclient/entities/CosmosLocation.java @@ -0,0 +1,24 @@ +package com.example.cosmosclient.entities; + +public class CosmosLocation { + private double latitude; + private double longitude; + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + public double getLatitude() { + return latitude; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + public double getLongitude() { + return longitude; + } + + public int hashCode(){ + return (int)((latitude+90)/0.1)+(int)((longitude/0.1)*1800); + } +} diff --git a/app/src/main/java/com/example/cosmosclient/entities/Feature.java b/app/src/main/java/com/example/cosmosclient/entities/Feature.java index 1b505d7..6334026 100644 --- a/app/src/main/java/com/example/cosmosclient/entities/Feature.java +++ b/app/src/main/java/com/example/cosmosclient/entities/Feature.java @@ -3,7 +3,16 @@ public class Feature { private String genre; private int code; - private Location location = new Location(); + private CosmosLocation location = new CosmosLocation(); + private double latitude; + private double longitude; + + public void setLatitude(double latitude) { + location.setLatitude(latitude); + } + public void setLongitude(double longitude) { + location.setLongitude(longitude); + } public String getGenre() { return genre; @@ -19,10 +28,10 @@ return this.code; } - public void setLocation(Location location){ + public void setLocation(CosmosLocation location){ this.location = location; } - public Location getLocation(){ + public CosmosLocation getLocation(){ return this.location; } } diff --git a/app/src/main/java/com/example/cosmosclient/entities/Location.java b/app/src/main/java/com/example/cosmosclient/entities/Location.java deleted file mode 100644 index 113b555..0000000 --- a/app/src/main/java/com/example/cosmosclient/entities/Location.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.example.cosmosclient.entities; - -public class Location { - private double latitude; - private double longitude; - - public void setLatitude(double latitude) { - this.latitude = latitude; - } - public double getLatitude() { - return latitude; - } - - public void setLongitude(double longitude) { - this.longitude = longitude; - } - public double getLongitude() { - return longitude; - } - - public int hashCode(){ - return (int)((latitude+90)/0.1)+(int)((longitude/0.1)*1800); - } -} diff --git a/app/src/main/java/com/example/cosmosclient/entities/ShopsResponse.java b/app/src/main/java/com/example/cosmosclient/entities/ShopsResponse.java new file mode 100644 index 0000000..ded01e5 --- /dev/null +++ b/app/src/main/java/com/example/cosmosclient/entities/ShopsResponse.java @@ -0,0 +1,9 @@ +package com.example.cosmosclient.entities; + +import java.util.ArrayList; + +public class ShopsResponse { + public ArrayList shops = new ArrayList<>(); + + +} diff --git a/app/src/main/java/com/example/cosmosclient/entities/shops.java b/app/src/main/java/com/example/cosmosclient/entities/shops.java new file mode 100644 index 0000000..a7191cc --- /dev/null +++ b/app/src/main/java/com/example/cosmosclient/entities/shops.java @@ -0,0 +1,8 @@ +package com.example.cosmosclient.entities; + +public class shops { + public String genre; + public int code; + public double latitude; + public double longitude; +} diff --git a/app/src/main/java/com/example/cosmosclient/resources/LocationRest.java b/app/src/main/java/com/example/cosmosclient/resources/LocationRest.java index 6109a92..e3c6110 100644 --- a/app/src/main/java/com/example/cosmosclient/resources/LocationRest.java +++ b/app/src/main/java/com/example/cosmosclient/resources/LocationRest.java @@ -1,19 +1,20 @@ package com.example.cosmosclient.resources; import com.example.cosmosclient.entities.AreaInformation; +import com.example.cosmosclient.entities.ShopsResponse; import retrofit2.Call; -import retrofit2.http.POST; +import retrofit2.http.GET; import retrofit2.http.Field; import retrofit2.http.FormUrlEncoded; +import retrofit2.http.Query; public interface LocationRest { - @POST("location") - @FormUrlEncoded - Call LocationService(@Field("leftLatitude") double leftLat, - @Field("leftLongitude") double leftLon, - @Field("rightLatitude") double rightLat, - @Field("rightLongitude") double rightLon); + @GET("shops") + Call LocationService(@Query("leftLatitude") String leftLat, + @Query("leftLongitude") String leftLon, + @Query("rightLatitude") String rightLat, + @Query("rightLongitude") String rightLon); } diff --git a/app/src/main/java/com/example/cosmosclient/services/CosomosBackgroundService.java b/app/src/main/java/com/example/cosmosclient/services/CosomosBackgroundService.java index b301dd4..a0f6422 100644 --- a/app/src/main/java/com/example/cosmosclient/services/CosomosBackgroundService.java +++ b/app/src/main/java/com/example/cosmosclient/services/CosomosBackgroundService.java @@ -28,7 +28,9 @@ import com.example.cosmosclient.entities.Group; import com.example.cosmosclient.entities.GroupListResponse; import com.example.cosmosclient.entities.RequestList; +import com.example.cosmosclient.entities.ShopsResponse; import com.example.cosmosclient.entities.jsons.GroupJson; +import com.example.cosmosclient.entities.CosmosLocation; import com.example.cosmosclient.resources.GroupsRest; import com.example.cosmosclient.resources.LocationRest; @@ -47,10 +49,11 @@ public class CosomosBackgroundService extends IntentService implements LocationListener { private Context context; private LocationManager locationManager; - private Location LOC; + private CosmosLocation LOC = new CosmosLocation(); private double leftLat,leftLon,rightLat,rightLon; //ここに計算予定 private static final int MinTime = 1000;/*最小時間間隔*/ private static final float MinDistance = 1;/*最小距離間隔*/ + private int count = 0; public CosomosBackgroundService() { super("CosomosBackgroundService"); @@ -169,9 +172,16 @@ // Log.d("debug", "onLocationChanged"); Log.d("debug", "lat:" + location.getLatitude()); Log.d("debug", "lon:" + location.getLongitude()); + Cosmos app = (Cosmos) getApplication(); + count = 0; LOC.setLatitude(location.getLatitude()); LOC.setLongitude(location.getLongitude()); - if(LOC.hashCode() == 0){ + for(int i = 0;i call = LocationService.LocationService(leftLat,leftLon,rightLat,rightLon); + Call call = LocationService.LocationService(String.valueOf(leftLat), + String.valueOf(leftLon),String.valueOf(rightLat),String.valueOf(rightLon)); //サーバからデータ受け取り - call.enqueue(new Callback() { + call.enqueue(new Callback() { //成功時 @Override - public void onResponse(Call call, Response response) { + public void onResponse(Call call, Response response) { if (response.isSuccessful()) { - AreaInformation result = response.body(); + ShopsResponse result = response.body(); //app/Cosmosに情報保存 Cosmos app = (Cosmos) getApplication(); - app.setAreaInfo(result.getLocation().hashCode(),result); +// app.setAreaInfo(result.getLocation().hashCode(),result); } else { //onFailureでキャッチできないエラー用 @@ -210,7 +221,7 @@ //失敗時 @Override - public void onFailure(Call call, Throwable t) { + public void onFailure(Call call, Throwable t) { t.printStackTrace(); Toast.makeText(CosomosBackgroundService.this, "区画情報の更新に失敗しました", Toast.LENGTH_SHORT).show();