diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index df8ac75..7184be9 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -81,11 +81,11 @@
android:name=".MainActivity"
android:exported="true"
android:label="@string/title_activity_maps">
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
diff --git a/app/src/main/java/com/example/nemophila/MainActivity.java b/app/src/main/java/com/example/nemophila/MainActivity.java
index e50541f..f807b46 100644
--- a/app/src/main/java/com/example/nemophila/MainActivity.java
+++ b/app/src/main/java/com/example/nemophila/MainActivity.java
@@ -6,6 +6,7 @@
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
+import androidx.lifecycle.ViewModelProvider;
import android.app.ProgressDialog;
import android.os.Bundle;
@@ -22,6 +23,8 @@
import android.util.Log;
import android.Manifest;
+import com.example.nemophila.entities.Shop;
+import com.example.nemophila.viewmodels.ShopsViewModel;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
@@ -37,13 +40,15 @@
import com.example.nemophila.databinding.ActivityMainBinding;
public class MainActivity extends FragmentActivity implements OnMapReadyCallback,LocationListener {
-
+ Nemophila nemophila;
private GoogleMap mMap;
private ActivityMainBinding binding;
private LatLng currentLatlng = null;
private LatLng testLatlng;
private LatLng testLatlng2;
private LatLng initialLatlng;
+ private LatLng shopLatlng;
+
private GroundOverlay currentOverlay;
LocationManager locationManager;
@@ -53,10 +58,11 @@
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
-
binding = ActivityMainBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
+ nemophila = (Nemophila) this.getApplication();
+
//現在地ボタン
ImageButton button1 = findViewById(R.id.currentButton);
// lambda式
@@ -92,13 +98,37 @@
assert mapFragment != null;
mapFragment.getMapAsync(this);
-
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
+ //ViewModelへのアクセス
+ ShopsViewModel shopsViewModel = new ViewModelProvider(this).get(ShopsViewModel.class);
+ //ダミーショップaとcが返される座標にしておく
+ //画面スクロールに応じて以下の1行を実行するようにする
+ shopsViewModel.setViewArea(20.0, 40.0, 10.0, 30.0);
+
+ // LiveDataへの購読
+ shopsViewModel.getShopsLiveData().observe(this, shops -> {
+ //受け取ったshopsに対してMarkerが立っているかを確認
+ //対応するMarkerがなければMarkerを立てる
+ for(Shop shop:shops) {
+ if(shopsViewModel.getMarker(shop)==null){
+ shopLatlng = new LatLng(shop.getLatitude(), shop.getLongitude());
+ System.out.println(shopLatlng);
+ Marker createMaker = mMap.addMarker(new MarkerOptions().position(shopLatlng).title(""));
+ //マーカーに店情報を持たせる
+ createMaker.setTag(shop);
+ //ShopToMarkerに紐づけ
+ shopsViewModel.setShopAndMarker(shop,createMaker);
+ }
+ }
+
+ });
+
+
//研究室周辺の緯度経度
double latitude = 34.7308032;
double longitude = 135.2630272;
@@ -108,10 +138,14 @@
testLatlng2 = new LatLng(34.74, 135.26);
//初期画面の座標(現在地をロードするまで)
- initialLatlng = new LatLng(39,138);
+// initialLatlng = new LatLng(39,138);
+ //店Cの座標にカメラ移動
+ initialLatlng = new LatLng(34.5,12.3);
//初期画面に移動
- mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(initialLatlng, 5f));
+// mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(initialLatlng, 5f));
+ mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(initialLatlng, 15f));
+
//標準のマーカー(店用のピン)
setMarker(latitude, longitude);
@@ -135,7 +169,7 @@
//長押し時に店を作成し、その座標にピンを立てる
//長押し時にその座標を保存し、投稿画面に移り、Shop作成完了時にはピンを立て、Shop画面に移行
mMap.setOnMapLongClickListener(longpushLocation -> {
- Nemophila nemophila = (Nemophila) this.getApplication();
+ // Nemophila nemophila = (Nemophila) this.getApplication();
//長押しされた位置の緯度経度を取得
//LatLng newlocation = new LatLng(longpushLocation.latitude, longpushLocation.longitude);
//Nemophilaに座標を保存
@@ -149,15 +183,15 @@
//遷移先でShopの作成中...
- //Shopの作成が完了した場合。if~
- //作成した店の座標を受け取る
- LatLng newlocation = new LatLng(nemophila.getCurrentLatitude(), nemophila.getCurrentLongitude());
- //ピンをその座標に立て、緯度経度をタイトルに設定
- //タイトルはnullにする予定
- //↓返り値でMarkerを返すので、Nemophilaに渡す予定
- Marker createMaker = mMap.addMarker(new MarkerOptions().position(newlocation).title(""+nemophila.getCurrentLatitude()+" :"+ nemophila.getCurrentLongitude()));
- //ピンを立てた位置にカメラを移動
- mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(newlocation, 18));
+// //Shopの作成が完了した場合。if~
+// //作成した店の座標を受け取る
+// LatLng newlocation = new LatLng(nemophila.getCurrentLatitude(), nemophila.getCurrentLongitude());
+// //ピンをその座標に立て、緯度経度をタイトルに設定
+// //タイトルはnullにする予定
+// //↓返り値でMarkerを返すので、Nemophilaに渡す予定
+// Marker createMaker = mMap.addMarker(new MarkerOptions().position(newlocation).title(""+nemophila.getCurrentLatitude()+" :"+ nemophila.getCurrentLongitude()));
+// //ピンを立てた位置にカメラを移動
+// mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(newlocation, 15));
});
@@ -170,6 +204,11 @@
//下からクリックしたことを通知
Toast.makeText(MainActivity.this, "ピンクリック", Toast.LENGTH_SHORT).show();
+ //選んだ店をsetする(現状はnullになっているが後で直す)
+ nemophila.setCurrentShop((Shop)marker.getTag());
+ System.out.println(nemophila.getCurrentShop().getName());
+
+
return false;
}
});
@@ -317,7 +356,7 @@
public void onLocationChanged(Location location) {
//初期画面は現在地を中心にするため...
if (currentLatlng == null){
- zoomMap(location.getLatitude(), location.getLongitude());
+ //zoomMap(location.getLatitude(), location.getLongitude());
findViewById(R.id.LL_Load).setVisibility(View.GONE);
}