菊池
マップでDirectionの表示をするコードは入れました。(機能はしていません) できればDirectionAPIのキーをコメントで指定している部分に入れておくか、自分に送ってくれると助かります。もしできなかった場合はすぐに言ってください お願いします
This commit is contained in:
parent
9bad03da2d
commit
b77c78f9dd
|
@ -4,6 +4,7 @@
|
|||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="testRunner" value="GRADLE" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="gradleJvm" value="jbr-17" />
|
||||
<option name="modules">
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
|
||||
<!-- インターネットへのアクセス権限 -->
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
|
||||
<application
|
||||
|
|
|
@ -88,6 +88,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
|||
// クリック処理
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
|
||||
// ID作成のクリック処理
|
||||
if(view == creatUUID){
|
||||
imageUuid.setImageResource(R.drawable.ischecked_uuid);
|
||||
|
@ -101,13 +102,15 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
|||
if(view == setUp){
|
||||
imageSetup.setImageResource(R.drawable.ischecked_uuid);
|
||||
Intent toSetup = new Intent(MainActivity.this,SetUpActivity.class);
|
||||
startActivity(toSetup);
|
||||
startActivityForResult(toSetup,100);
|
||||
overridePendingTransition(android.R.anim.slide_in_left,android.R.anim.slide_out_right);
|
||||
finish(); // 画面遷移後元の状態に戻す
|
||||
}
|
||||
if (view == imageSetup){
|
||||
imageSetup.setImageResource(R.drawable.ischecked_uuid);
|
||||
Intent toSetup = new Intent(MainActivity.this,SetUpActivity.class);
|
||||
startActivity(toSetup);
|
||||
startActivityForResult(toSetup,100);
|
||||
overridePendingTransition(android.R.anim.slide_in_left,android.R.anim.slide_out_right);
|
||||
finish(); // 画面遷移後元の状態に戻す
|
||||
}
|
||||
|
||||
|
@ -152,6 +155,9 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
|||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
Log.d("DialogNO", "DialogでNoが選ばれました");
|
||||
|
||||
// Noを押したら、元の画像に戻す処理
|
||||
imageUuid.setImageResource(R.drawable.checked_image);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -1,52 +1,49 @@
|
|||
package com.example.oplogy;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.media.Image;
|
||||
import android.location.Location;
|
||||
import android.location.LocationListener;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.google.android.gms.maps.CameraUpdateFactory;
|
||||
import com.google.android.gms.maps.GoogleMap;
|
||||
import com.google.android.gms.maps.OnMapReadyCallback;
|
||||
import com.google.android.gms.maps.SupportMapFragment;
|
||||
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
|
||||
import com.google.android.gms.maps.model.LatLng;
|
||||
import com.google.android.gms.maps.model.Marker;
|
||||
import com.google.android.gms.maps.model.LatLngBounds;
|
||||
import com.google.android.gms.maps.model.MarkerOptions;
|
||||
import com.example.oplogy.databinding.MapsBinding;
|
||||
import com.google.android.gms.maps.model.Polyline;
|
||||
import com.google.android.gms.maps.model.PolylineOptions;
|
||||
import com.google.maps.DirectionsApi;
|
||||
import com.google.maps.DirectionsApiRequest;
|
||||
import com.google.maps.GeoApiContext;
|
||||
import com.google.maps.model.DirectionsResult;
|
||||
import com.google.maps.model.DirectionsRoute;
|
||||
import com.google.maps.model.TravelMode;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Maps extends FragmentActivity implements OnMapReadyCallback,View.OnClickListener{
|
||||
public class Maps extends FragmentActivity implements OnMapReadyCallback, View.OnClickListener, LocationListener {
|
||||
|
||||
// ボタンの戻る処理
|
||||
private static final String TAG = "MapsActivity";
|
||||
ImageView backMain;
|
||||
private GoogleMap mMap;
|
||||
private MapsBinding binding;
|
||||
|
||||
private LatLng loc;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
binding = MapsBinding.inflate(getLayoutInflater());
|
||||
setContentView(binding.getRoot());
|
||||
binding = MapsBinding.inflate(getLayoutInflater());
|
||||
setContentView(binding.getRoot());
|
||||
|
||||
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
|
||||
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
|
||||
.findFragmentById(R.id.map);
|
||||
mapFragment.getMapAsync(this);
|
||||
|
@ -55,66 +52,73 @@ public class Maps extends FragmentActivity implements OnMapReadyCallback,View.On
|
|||
backMain.setOnClickListener(this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Manipulates the map once available.
|
||||
* This callback is triggered when the map is ready to be used.
|
||||
* This is where we can add markers or lines, add listeners or move the camera. In this case,
|
||||
* we just add a marker near Sydney, Australia.
|
||||
* If Google Play services is not installed on the device, the user will be prompted to install
|
||||
* it inside the SupportMapFragment. This method will only be triggered once the user has
|
||||
* installed Google Play services and returned to the app.
|
||||
*/
|
||||
@Override
|
||||
public void onMapReady(GoogleMap googleMap) {
|
||||
mMap = googleMap;
|
||||
|
||||
/// 地図の倍率を指定
|
||||
LatLng startPoint = new LatLng(35.09050879999539, 136.87845379325216);
|
||||
LatLng endPoint = new LatLng(35.09364708442631, 136.88171563326418);
|
||||
|
||||
// ↓ここに地点の処理を書いておく↓
|
||||
// Add a marker in Sydney and move the camera
|
||||
loc = new LatLng(35.09050879999539, 136.87845379325216);
|
||||
mMap.addMarker(new MarkerOptions().position(loc).title("名古屋港水族館"));
|
||||
/// 表示位置を地図に指定
|
||||
mMap.moveCamera(CameraUpdateFactory.newLatLng(loc));
|
||||
addNumberedMarker(startPoint, "1: 名古屋港水族館");
|
||||
addNumberedMarker(new LatLng(35.09284820618655, 136.88165119390393), "2: Waypoint");
|
||||
addNumberedMarker(endPoint, "3: Destination");
|
||||
|
||||
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(loc, 17));
|
||||
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(startPoint, 17));
|
||||
|
||||
LatLng startLatLng = new LatLng(35.09050879999539, 136.87845379325216);
|
||||
LatLng secandLatLng = new LatLng(35.09284820618655, 136.88165119390393);
|
||||
LatLng thirdLatLng = new LatLng(35.09364708442631, 136.88171563326418);
|
||||
// Directions API リクエスト
|
||||
new Thread(() -> {
|
||||
try {
|
||||
DirectionsResult result = DirectionsApi.newRequest(new GeoApiContext.Builder()
|
||||
.apiKey("AIzaSyBQ1Ak-I2NL5TP4K59ZI0VgzKk6HNZuusw") // DirectionsAPIキーの取得
|
||||
.build())
|
||||
.mode(TravelMode.DRIVING)
|
||||
.origin(new com.google.maps.model.LatLng(startPoint.latitude, startPoint.longitude))
|
||||
.destination(new com.google.maps.model.LatLng(endPoint.latitude, endPoint.longitude))
|
||||
.await();
|
||||
|
||||
if (result.routes != null && result.routes.length > 0) {
|
||||
DirectionsRoute route = result.routes[0];
|
||||
|
||||
Marker startMaker = mMap.addMarker(new MarkerOptions()
|
||||
.position(startLatLng)
|
||||
.title("名古屋港水族館")
|
||||
);
|
||||
List<LatLng> decodedPath = new ArrayList<>();
|
||||
for (com.google.maps.model.LatLng point : route.overviewPolyline.decodePath()) {
|
||||
decodedPath.add(new LatLng(point.lat, point.lng));
|
||||
}
|
||||
|
||||
Marker secondMaker = mMap.addMarker(new MarkerOptions()
|
||||
.position(secandLatLng)
|
||||
.title("2番目")
|
||||
);
|
||||
runOnUiThread(() -> {
|
||||
PolylineOptions polylineOptions = new PolylineOptions().addAll(decodedPath).color(Color.BLUE).width(10);
|
||||
mMap.addPolyline(polylineOptions);
|
||||
|
||||
Marker thirdMaker = mMap.addMarker(new MarkerOptions()
|
||||
.position(thirdLatLng)
|
||||
.title("3番目")
|
||||
);
|
||||
|
||||
drowRoute(startLatLng,secandLatLng,thirdLatLng);
|
||||
mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(
|
||||
LatLngBounds.builder().include(startPoint).include(endPoint).build(), 100));
|
||||
});
|
||||
} else {
|
||||
Log.e(TAG, "No routes found");
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Log.e(TAG, "Error fetching directions", ex);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
private void drowRoute(LatLng startLatLng,LatLng secondLatLung,LatLng thirdLatLng){
|
||||
GeoApiContext context = new GeoApiContext.Builder()
|
||||
.apiKey("AIzaSyBQ1Ak-I2NL5TP4K59ZI0VgzKk6HNZuusw")
|
||||
.build();
|
||||
// ここで入れている地点に、番号を振っている
|
||||
private void addNumberedMarker(LatLng position, String title) {
|
||||
mMap.addMarker(new MarkerOptions().position(position).title(title));
|
||||
}
|
||||
|
||||
|
||||
// クリックするとメイン画面に戻る処理
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if(view == backMain){
|
||||
Intent backMain = new Intent(Maps.this,MainActivity.class);
|
||||
if (view == backMain) {
|
||||
Intent backMain = new Intent(Maps.this, MainActivity.class);
|
||||
startActivity(backMain);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// LocationListenerの呼び出し時に実装するもの
|
||||
@Override
|
||||
public void onLocationChanged(@NonNull Location location) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -89,7 +89,8 @@ public class SetUpActivity extends FragmentActivity
|
|||
|
||||
toMain.setOnClickListener(view -> {
|
||||
Intent intent = new Intent(SetUpActivity.this,MainActivity.class); //main画面へ戻る処理
|
||||
startActivity(intent);
|
||||
startActivityForResult(intent,100);
|
||||
overridePendingTransition(android.R.anim.slide_in_left,android.R.anim.slide_out_right);
|
||||
});
|
||||
|
||||
setUp.setOnClickListener(view -> {
|
||||
|
|
Loading…
Reference in New Issue
Block a user