diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index dc3df27..53aecf0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -41,13 +41,12 @@ android:name=".SignUpActivity" android:exported="true" android:label="@string/title_activity_sign_up"> - - - + + - - + + - - + + - - + + diff --git a/app/src/main/java/com/example/nemophila/MainActivity.java b/app/src/main/java/com/example/nemophila/MainActivity.java index c3769c7..36bae73 100644 --- a/app/src/main/java/com/example/nemophila/MainActivity.java +++ b/app/src/main/java/com/example/nemophila/MainActivity.java @@ -1,6 +1,5 @@ package com.example.nemophila; -import androidx.core.content.res.ResourcesCompat; import androidx.fragment.app.FragmentActivity; import androidx.activity.result.ActivityResultLauncher; @@ -8,19 +7,14 @@ import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.graphics.Canvas; -import android.graphics.Point; -import android.graphics.drawable.Drawable; import android.os.Bundle; +import android.widget.ImageButton; import android.widget.Toast; import android.annotation.SuppressLint; import android.content.pm.PackageManager; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; -import android.widget.TextView; import android.content.Intent; import android.provider.Settings; import android.util.Log; @@ -28,12 +22,10 @@ import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; -import com.google.android.gms.maps.MapView; import com.google.android.gms.maps.OnMapReadyCallback; import com.google.android.gms.maps.SupportMapFragment; import com.google.android.gms.maps.model.BitmapDescriptor; import com.google.android.gms.maps.model.BitmapDescriptorFactory; -import com.google.android.gms.maps.model.CameraPosition; import com.google.android.gms.maps.model.GroundOverlay; import com.google.android.gms.maps.model.GroundOverlayOptions; import com.google.android.gms.maps.model.LatLng; @@ -41,21 +33,19 @@ import com.google.android.gms.maps.model.Marker; import com.google.android.gms.maps.model.MarkerOptions; import com.example.nemophila.databinding.ActivityMainBinding; -import com.google.firebase.firestore.GeoPoint; - -import java.util.Map; public class MainActivity extends FragmentActivity implements OnMapReadyCallback,LocationListener { private GoogleMap mMap; private ActivityMainBinding binding; - private LatLng latlng; - private LatLng latlng2; + private LatLng currentLatlng; + private LatLng testLatlng; + private LatLng testLatlng2; - private GroundOverlay current_overlay; + private GroundOverlay currentOverlay; LocationManager locationManager; - + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -65,6 +55,16 @@ binding = ActivityMainBinding.inflate(getLayoutInflater()); setContentView(binding.getRoot()); + + ImageButton button1 = findViewById(R.id.currentButton); + // lambda式 + button1.setOnClickListener( v -> { + Log.d("debug", "currentbutton, 現在地にカメラを移動"); + //現在地にカメラを移動 + zoomMap(currentLatlng.latitude, currentLatlng.longitude); + }); + + if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { @@ -93,9 +93,9 @@ double latitude = 34.7308032; double longitude = 135.2630272; - //テスト用 - latlng = new LatLng(latitude, longitude); - latlng2 = new LatLng(34.74, 135.26); + //テスト用,仮ピン立て + testLatlng = new LatLng(latitude, longitude); + testLatlng2 = new LatLng(34.74, 135.26); //標準のマーカー(店用のピン) setMarker(latitude, longitude); @@ -168,12 +168,12 @@ MarkerOptions markerOptions = new MarkerOptions(); MarkerOptions markerOptions2 = new MarkerOptions(); - markerOptions.position(latlng); + markerOptions.position(testLatlng); markerOptions.title("ntlab"); mMap.addMarker(markerOptions); //テスト用 - markerOptions2.position(latlng2); + markerOptions2.position(testLatlng2); markerOptions2.title(null); mMap.addMarker(markerOptions2); @@ -189,6 +189,8 @@ double north = latitude * (1+0.00005); double east = longitude * (1+0.00005); + LatLng latlng = new LatLng(latitude,longitude); + // LatLngBounds (LatLng southwest, LatLng northeast) //左下、右上 LatLngBounds bounds = LatLngBounds.builder() @@ -207,11 +209,12 @@ mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latlng, 15f)); } + //現在地の表示 private void setIcon(double latitude, double longitude){ //Drawable ic_current = ResourcesCompat.getDrawable(getResources(),R.drawable.icon_current,null); //更新前の現在地アイコンを消去 - if(current_overlay != null) { - current_overlay.remove(); + if(currentOverlay != null) { + currentOverlay.remove(); } LatLng current_location = new LatLng(latitude,longitude); @@ -233,14 +236,14 @@ overlayOptions.position(current_location, 200f, 200f); // マップに貼り付け・アルファを設定 - current_overlay = mMap.addGroundOverlay(overlayOptions); + currentOverlay = mMap.addGroundOverlay(overlayOptions); // カメラを移動 - zoomMap(latitude, longitude); + //zoomMap(latitude, longitude); // 透明度 - assert current_overlay != null; - current_overlay.setTransparency(0.8F); + assert currentOverlay != null; + currentOverlay.setTransparency(0.8F); } @@ -301,25 +304,27 @@ public void onLocationChanged(Location location) { //現在地が変更されるたびに現在地アイコンを移動 //LatLng型で一応受け取っておく - latlng = new LatLng(location.getLatitude(), location.getLongitude()); + currentLatlng = new LatLng(location.getLatitude(), location.getLongitude()); /* テスト用。現在座標を画面に表示 */ - // 緯度の表示 - TextView textView1 = findViewById(R.id.text_view1); - String str1 = "Latitude:"+location.getLatitude(); - textView1.setText(str1); - - // 経度の表示 - TextView textView2 = findViewById(R.id.text_view2); - String str2 = "Longitude:"+location.getLongitude(); - textView2.setText(str2); +// // 緯度の表示 +// TextView textView1 = findViewById(R.id.text_view1); +// String str1 = "Latitude:"+location.getLatitude(); +// textView1.setText(str1); +// +// // 経度の表示 +// TextView textView2 = findViewById(R.id.text_view2); +// String str2 = "Longitude:"+location.getLongitude(); +// textView2.setText(str2); //現在地アイコンを表示.このsetIcon内にzoomMap処理もあるので注意 setIcon(location.getLatitude(),location.getLongitude()); } + + @Override public void onProviderEnabled(String provider) { @@ -329,4 +334,5 @@ public void onProviderDisabled(String provider) { } + } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 95d4392..5736918 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -13,17 +13,38 @@ android:layout_height="match_parent" tools:context=".MainActivity" /> - + android:layout_height="match_parent"> - + + + + + + + + + + + + + + + + + + + + \ No newline at end of file