Merge pull request #78 from nitta-lab-2023/test_map7
Test map7
commit 5bad232e378be63cbb87bd5e3a88317451239037
2 parents b95f746 + 37c4131
Shinnosuke Iyonaga authored on 20 Jun 2023
Showing 3 changed files
View
18
app/src/main/AndroidManifest.xml
<activity
android:name=".SignUpActivity"
android:exported="true"
android:label="@string/title_activity_sign_up">
 
<!-- <intent-filter>-->
<!-- <action android:name="android.intent.action.MAIN" />-->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
 
 
<!-- <category android:name="android.intent.category.LAUNCHER" />-->
<!-- </intent-filter>-->
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".LoginActivity"
android:exported="true"
<activity
android:name=".ShopActivity"
android:exported="true"
android:label="@string/title_activity_shop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<!-- <intent-filter>-->
<!-- <action android:name="android.intent.action.MAIN" />-->
 
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!-- <category android:name="android.intent.category.LAUNCHER" />-->
<!-- </intent-filter>-->
</activity>
</application>
 
</manifest>
View
81
app/src/main/java/com/example/nemophila/MainActivity.java
package com.example.nemophila;
 
import androidx.core.content.res.ResourcesCompat;
import androidx.fragment.app.FragmentActivity;
 
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
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;
import android.Manifest;
 
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;
import com.google.android.gms.maps.model.LatLngBounds;
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);
//現在地アイコンの取得
//Drawable ic_current = ResourcesCompat.getDrawable(getResources(),R.drawable.ic_current_location,null);
 
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) {
//研究室周辺の緯度経度
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);
 
private void setMarker(double latitude, double longitude){
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);
 
// ズーム
double west = longitude * (1-0.00005);
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()
.include(new LatLng(south , west))
//ズーム処理
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);
 
// public GroundOverlayOptions position(LatLng location, float width, float height)
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);
}
 
 
private final ActivityResultLauncher<String>
@Override
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) {
 
}
@Override
public void onProviderDisabled(String provider) {
 
}
 
}
View
app/src/main/res/layout/activity_main.xml