From 619b22dc02b771adedb30bd278d33bbf7f8b0dfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Wed, 3 Jul 2024 15:46:11 +0900 Subject: [PATCH] =?UTF-8?q?Maps.java=E3=81=B8=E3=81=AE=E5=A4=89=E6=9B=B4?= =?UTF-8?q?=E3=82=92Revert?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/example/oplogy/Maps.java | 135 ++++++------------ 1 file changed, 45 insertions(+), 90 deletions(-) diff --git a/app/src/main/java/com/example/oplogy/Maps.java b/app/src/main/java/com/example/oplogy/Maps.java index 25c0239..48c827b 100644 --- a/app/src/main/java/com/example/oplogy/Maps.java +++ b/app/src/main/java/com/example/oplogy/Maps.java @@ -1,120 +1,75 @@ package com.example.oplogy; +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.webkit.WebSettings; +import android.webkit.WebView; +import android.webkit.WebViewClient; +import android.widget.ImageView; + import androidx.fragment.app.FragmentActivity; -import android.content.Intent; -import android.graphics.Color; -import android.media.Image; -import android.os.Bundle; -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.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 java.util.Locale; -import java.util.Map; +public class Maps extends FragmentActivity implements View.OnClickListener { -public class Maps extends FragmentActivity implements OnMapReadyCallback,View.OnClickListener{ - - // ボタンの戻る処理 + private WebView webView; 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()); - - // 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); + binding = MapsBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); backMain = findViewById(R.id.BackMain); backMain.setOnClickListener(this); + + webView = findViewById(R.id.webView); + WebSettings webSettings = webView.getSettings(); + webSettings.setJavaScriptEnabled(true); + webView.setWebViewClient(new WebViewClient()); + +// ここにデータを入れておいてください、処理は[/]で区切っています + loadMapInWebView("35.09050879999539,136.87845379325216/35.09284820618655,136.88165119390393/35.09364708442631,136.88171563326418"); } +// WebViewの処理です(Mapの中の処理をやっています) + private void loadMapInWebView(String locations) { +// 区切ることで、追加の地点を入れて、最終地点にピンを打ってある状態です + String[] locArray = locations.split("/"); +// ↓URLで経路案内(車)での表示をしています + StringBuilder urlBuilder = new StringBuilder("https://www.google.com/maps/dir/?api=1&travelmode=driving"); + if (locArray.length > 0) { + urlBuilder.append("&origin=").append(locArray[0]); - /** - * 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; + if (locArray.length > 1) { + urlBuilder.append("&destination=").append(locArray[locArray.length - 1]); - /// 地図の倍率を指定 + if (locArray.length > 2) { + urlBuilder.append("&waypoints="); + for (int i = 1; i < locArray.length - 1; i++) { + urlBuilder.append(locArray[i]); + if (i < locArray.length - 2) { + urlBuilder.append("|"); + } + } + } + } + } - // ↓ここに地点の処理を書いておく↓ - // 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)); - - mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(loc, 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); - - - Marker startMaker = mMap.addMarker(new MarkerOptions() - .position(startLatLng) - .title("名古屋港水族館") - ); - - Marker secondMaker = mMap.addMarker(new MarkerOptions() - .position(secandLatLng) - .title("2番目") - ); - - Marker thirdMaker = mMap.addMarker(new MarkerOptions() - .position(thirdLatLng) - .title("3番目") - ); - - drowRoute(startLatLng,secandLatLng,thirdLatLng); - } - - private void drowRoute(LatLng startLatLng,LatLng secondLatLung,LatLng thirdLatLng){ - GeoApiContext context = new GeoApiContext.Builder() - .apiKey("AIzaSyBQ1Ak-I2NL5TP4K59ZI0VgzKk6HNZuusw") - .build(); + webView.loadUrl(urlBuilder.toString()); } @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); } } -} \ No newline at end of file +}