Advertisement
Guest User

MainActivity.java

a guest
Nov 14th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. package com.example.locationandmap;
  2.  
  3. import android.support.v4.app.FragmentActivity;
  4. import android.os.Bundle;
  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. public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
  14.  
  15. private GoogleMap mMap;
  16.  
  17. @Override
  18. protected void onCreate(Bundle savedInstanceState) {
  19.  
  20. super.onCreate(savedInstanceState);
  21. setContentView(R.layout.activity_maps);
  22. // Obtain the SupportMapFragment and get notified when the map is ready to be used.
  23. SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
  24. .findFragmentById(R.id.map);
  25. if (mapFragment != null) {
  26. mapFragment.getMapAsync(this);
  27. }
  28. }
  29.  
  30.  
  31. /**
  32. * Manipulates the map once available.
  33. * This callback is triggered when the map is ready to be used.
  34. * This is where we can add markers or lines, add listeners or move the camera. In this case,
  35. * we just add a marker near Sydney, Australia.
  36. * If Google Play services is not installed on the device, the user will be prompted to install
  37. * it inside the SupportMapFragment. This method will only be triggered once the user has
  38. * installed Google Play services and returned to the app.
  39. */
  40. @Override
  41. public void onMapReady(GoogleMap googleMap) {
  42. mMap = googleMap;
  43.  
  44. // Add a marker in Sydney and move the camera
  45. LatLng sydney = new LatLng(-34, 151);
  46. mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
  47. mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement