MeteoriteDB

Log | Files | Refs | README

commit 58e2c0666b5b95db348f88a322ed584318e1ae07
parent ac0139edfc9d71468f7233eabde1c179e3a4083b
Author: William Lindholm <william_lindholm@outlook.com>
Date:   Thu,  4 May 2023 20:45:55 +0200

Launching map fragment onCreate, known problem: mapFragment hides other views.

Diffstat:
Mapp/src/main/java/com/example/project_assignment/MeteoriteActivity.java | 31+++++++++++++++++++++++++++++--
1 file changed, 29 insertions(+), 2 deletions(-)

diff --git a/app/src/main/java/com/example/project_assignment/MeteoriteActivity.java b/app/src/main/java/com/example/project_assignment/MeteoriteActivity.java @@ -1,12 +1,23 @@ package com.example.project_assignment; +import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import android.content.Intent; import android.os.Bundle; import android.widget.TextView; -public class MeteoriteActivity extends AppCompatActivity { +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.LatLng; +import com.google.android.gms.maps.model.MarkerOptions; + +public class MeteoriteActivity extends AppCompatActivity implements OnMapReadyCallback { + + + private Meteorite meteorite; @Override protected void onCreate(Bundle savedInstanceState) { @@ -14,7 +25,23 @@ public class MeteoriteActivity extends AppCompatActivity { setContentView(R.layout.activity_meteorite); Intent intent = getIntent(); - Meteorite meteorite = (Meteorite) intent.getParcelableExtra("meteorite"); + meteorite = (Meteorite) intent.getParcelableExtra("meteorite"); + + TextView title = findViewById(R.id.textview_meteoriteTitle); + TextView info = findViewById(R.id.textview_meteoriteInfo); + title.setText(meteorite.name); + info.setText(meteorite.toString()); + + SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.mapFragment); + mapFragment.getMapAsync(this); + } + + @Override + public void onMapReady(@NonNull GoogleMap googleMap) { + Double.parseDouble(meteorite.latitude); + googleMap.addMarker(new MarkerOptions().position(new LatLng(Double.parseDouble(meteorite.latitude), Double.parseDouble(meteorite.longitude))).title("Marker")); + float zoom = 4; + googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(Double.parseDouble(meteorite.latitude), Double.parseDouble(meteorite.longitude)), zoom)); } } \ No newline at end of file