package com.example.googlemaps; import androidx.fragment.app.FragmentActivity; import android.os.Bundle; 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.MarkerOptions; public class MainActivity extends FragmentActivity implements OnMapReadyCallback { private GoogleMap mMap; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // 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); } /** * 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; mMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN); // map with mountains, rivers, etc // mMap.setMapType(GoogleMap.MAP_TYPE_HYBRID); // photographic map + roads and city names // mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE); // photographic map mMap.addMarker(new MarkerOptions() .position(new LatLng(37.4233438, -122.0728817)) .title("LinkedIn") .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN))); mMap.addMarker(new MarkerOptions() .position(new LatLng(37.4629101,-122.2449094)) .title("Facebook") .snippet("Facebook HQ: Menlo Park") .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE))); mMap.addMarker(new MarkerOptions() .position(new LatLng(37.3092293, -122.1136845)) .title("Apple") .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_VIOLET))); // Add a marker to CSUEB and move the camera to that location LatLng csueb = new LatLng(37.6571, -122.0574); mMap.addMarker(new MarkerOptions().position(csueb).title("Marker to CSUEB")); mMap.moveCamera(CameraUpdateFactory.newLatLng(csueb)); mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(37.6571, -122.0574), 10)); // change last parameter for more zoom, i.e. switch to 15 and look at difference } }