MeteoriteActivity.java (2055B)
1 package com.example.project_assignment; 2 3 import androidx.annotation.NonNull; 4 import androidx.appcompat.app.AppCompatActivity; 5 6 import android.content.Intent; 7 import android.os.Bundle; 8 import android.widget.TextView; 9 10 import com.google.android.gms.maps.CameraUpdateFactory; 11 import com.google.android.gms.maps.GoogleMap; 12 import com.google.android.gms.maps.OnMapReadyCallback; 13 import com.google.android.gms.maps.SupportMapFragment; 14 import com.google.android.gms.maps.model.LatLng; 15 import com.google.android.gms.maps.model.MarkerOptions; 16 17 public class MeteoriteActivity extends AppCompatActivity implements OnMapReadyCallback { 18 19 20 private Meteorite meteorite; 21 22 @Override 23 protected void onCreate(Bundle savedInstanceState) { 24 super.onCreate(savedInstanceState); 25 setContentView(R.layout.activity_meteorite); 26 27 // fetch all data sent using the intent. 28 Intent intent = getIntent(); 29 // unpack getParcelableExtra 30 meteorite = (Meteorite) intent.getParcelableExtra("meteorite"); 31 32 TextView title = findViewById(R.id.textview_meteoriteTitle); 33 TextView info = findViewById(R.id.textview_meteoriteInfo); 34 35 title.setText(meteorite.getName()); 36 info.setText(meteorite.getDescription()); 37 38 SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.mapFragment); 39 mapFragment.getMapAsync(this); 40 } 41 42 /** 43 * Initialize a google maps mapview, and set the location and marker to the meteorites location. 44 */ 45 @Override 46 public void onMapReady(@NonNull GoogleMap googleMap) { 47 Double.parseDouble(meteorite.getLatitude()); 48 googleMap.addMarker(new MarkerOptions().position(new LatLng(Double.parseDouble(meteorite.getLatitude()), Double.parseDouble(meteorite.getLongitude()))).title("Marker")); 49 float zoom = 4; 50 googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(Double.parseDouble(meteorite.getLatitude()), Double.parseDouble(meteorite.getLongitude())), zoom)); 51 } 52 }