|
| 1 | +package xyz.projectplay.googlemapsbottomsheetexample; |
| 2 | + |
| 3 | +import android.os.Bundle; |
| 4 | +import android.support.v4.app.FragmentActivity; |
| 5 | + |
| 6 | +import com.google.android.gms.maps.CameraUpdateFactory; |
| 7 | +import com.google.android.gms.maps.GoogleMap; |
| 8 | +import com.google.android.gms.maps.OnMapReadyCallback; |
| 9 | +import com.google.android.gms.maps.SupportMapFragment; |
| 10 | +import com.google.android.gms.maps.model.LatLng; |
| 11 | +import com.google.android.gms.maps.model.MarkerOptions; |
| 12 | + |
| 13 | +import xyz.projectplay.googlemapsbottomsheet.GoogleMapsBottomSheetBehavior; |
| 14 | + |
| 15 | +public class MapsActivity extends FragmentActivity implements OnMapReadyCallback { |
| 16 | + |
| 17 | + private GoogleMap mMap; |
| 18 | + private GoogleMapsBottomSheetBehavior behavior; |
| 19 | + |
| 20 | + @Override |
| 21 | + protected void onCreate(Bundle savedInstanceState) { |
| 22 | + super.onCreate(savedInstanceState); |
| 23 | + setContentView(R.layout.activity_maps); |
| 24 | + // Obtain the SupportMapFragment and get notified when the map is ready to be used. |
| 25 | + SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() |
| 26 | + .findFragmentById(R.id.map); |
| 27 | + mapFragment.getMapAsync(this); |
| 28 | + |
| 29 | + behavior = new GoogleMapsBottomSheetBehavior(this, null); |
| 30 | + } |
| 31 | + |
| 32 | + |
| 33 | + /** |
| 34 | + * Manipulates the map once available. |
| 35 | + * This callback is triggered when the map is ready to be used. |
| 36 | + * This is where we can add markers or lines, add listeners or move the camera. In this case, |
| 37 | + * we just add a marker near Sydney, Australia. |
| 38 | + * If Google Play services is not installed on the device, the user will be prompted to install |
| 39 | + * it inside the SupportMapFragment. This method will only be triggered once the user has |
| 40 | + * installed Google Play services and returned to the app. |
| 41 | + */ |
| 42 | + @Override |
| 43 | + public void onMapReady(GoogleMap googleMap) { |
| 44 | + mMap = googleMap; |
| 45 | + |
| 46 | + // Add a marker in Sydney and move the camera |
| 47 | + LatLng sydney = new LatLng(-34, 151); |
| 48 | + mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney")); |
| 49 | + mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney)); |
| 50 | + } |
| 51 | +} |
0 commit comments