diff --git a/app/src/main/java/com/example/nemophila/MainActivity.java b/app/src/main/java/com/example/nemophila/MainActivity.java index eb52653..c0cf3f9 100644 --- a/app/src/main/java/com/example/nemophila/MainActivity.java +++ b/app/src/main/java/com/example/nemophila/MainActivity.java @@ -49,14 +49,13 @@ private GoogleMap mMap; private ActivityMainBinding binding; private LatLng currentLatlng = null; - private LatLng testLatlng; - private LatLng testLatlng2; private LatLng initialLatlng; private LatLng shopLatlng; + private LatLng testLatlng; + private LatLng testLatlng2; private LatLng tapLatlng; private CameraPosition nowCamera; private LatLng nowLatlng; - private float nowZoom = 10f; private GroundOverlay currentOverlay; LocationManager locationManager; @@ -77,7 +76,6 @@ // lambda式 button1.setOnClickListener( v -> { Log.d("debug", "currentbutton, 現在地にカメラを移動"); - //shopsViewModel.setViewArea(currentLatlng.longitude+20, currentLatlng.latitude+20.0, currentLatlng.longitude-20.0, currentLatlng.latitude-20.0); System.out.println(shopsViewModel.getShopsLiveData().getValue()); //現在地にカメラを移動 zoomMap(currentLatlng.latitude, currentLatlng.longitude); @@ -117,8 +115,6 @@ //ViewModelへのアクセス shopsViewModel = new ViewModelProvider(this).get(ShopsViewModel.class); - //ダミーショップaとcが返される座標にしておく - shopsViewModel.setViewArea(40.0, 140.0, 20.0, 100.0); // LiveDataへの購読 shopsViewModel.getShopsLiveData().observe(this, shops -> { @@ -139,7 +135,7 @@ }); - +/* //研究室周辺の緯度経度 double latitude = 34.7308032; double longitude = 135.2630272; @@ -148,14 +144,8 @@ testLatlng = new LatLng(latitude, longitude); testLatlng2 = new LatLng(34.74, 135.26); - //初期画面の座標(現在地をロードするまで) - initialLatlng = new LatLng(39,138); //店Cの座標にカメラ移動 -// initialLatlng = new LatLng(34.5,12.3); - - //初期画面に移動 - mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(initialLatlng, 15f)); - + //initialLatlng = new LatLng(34.5,12.3); //標準のマーカー(店用のピン) //setMarker(latitude, longitude); @@ -163,15 +153,28 @@ //アイコン画像をマーカーに設定 //画像関連がわかっていないのでパス //setIcon(latitude, longitude); + */ + + //初期画面の座標(現在地をロードするまで表示) + //initialLatlng = new LatLng(39,138); + initialLatlng = new LatLng(nemophila.getCameraLatitude(),nemophila.getCameraLongitude()); + //初期画面に移動 + //mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(initialLatlng, 15f)); + mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(initialLatlng, nemophila.getZoom())); + //画面が動いたとき mMap.setOnCameraIdleListener(() -> { //カメラの座標とZOOM倍率を保存 - nowCamera = mMap.getCameraPosition(); - nowLatlng = new LatLng(nowCamera.target.latitude, nowCamera.target.longitude); - nowZoom = nowCamera.zoom; + //nowCamera = mMap.getCameraPosition(); + nemophila.setCameraLatitude(mMap.getCameraPosition().target.latitude); + nemophila.setCameraLongitude(mMap.getCameraPosition().target.longitude); + nemophila.setZoom(mMap.getCameraPosition().zoom); + + //nowLatlng = new LatLng(nowCamera.target.latitude, nowCamera.target.longitude); + //nowZoom = nowCamera.zoom; //Shopの描画範囲を指定 - shopsViewModel.setViewArea(nowLatlng.longitude+1, nowLatlng.latitude+1, nowLatlng.longitude-1, nowLatlng.latitude-1); + shopsViewModel.setViewArea(nemophila.getCameraLongitude()+1, nemophila.getCameraLatitude()+1, nemophila.getCameraLongitude()-1, nemophila.getCameraLatitude()-1); }); /* @@ -198,19 +201,6 @@ //ShopCreate画面に遷移 Intent intent = new Intent(MainActivity.this, ShopCreateActivity.class); startActivity(intent); - - //遷移先で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, 15)); - }); // ピンをクリックした場合 @@ -276,7 +266,7 @@ newLatLngBounds(bounds, width, height, 0)); //ズーム処理 - mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latlng, nowZoom)); + mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latlng, nemophila.getZoom())); } //現在地の表示 @@ -374,7 +364,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); }