Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. package info.androidtonight.googlemapintegration;
  2.  
  3. import android.Manifest;
  4. import android.content.pm.PackageManager;
  5. import android.support.v4.app.ActivityCompat;
  6. import android.support.v4.app.FragmentActivity;
  7. import android.os.Bundle;
  8.  
  9. import com.google.android.gms.maps.CameraUpdateFactory;
  10. import com.google.android.gms.maps.GoogleMap;
  11. import com.google.android.gms.maps.OnMapReadyCallback;
  12. import com.google.android.gms.maps.SupportMapFragment;
  13. import com.google.android.gms.maps.model.LatLng;
  14. import com.google.android.gms.maps.model.MarkerOptions;
  15.  
  16. public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
  17.  
  18. private GoogleMap mMap;
  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().findFragmentById(R.id.map);
  26. mapFragment.getMapAsync(this);
  27.  
  28. }
  29.  
  30. @Override
  31. public void onMapReady(GoogleMap googleMap) {
  32. mMap = googleMap;
  33.  
  34. // Add a marker in Sydney and move the camera
  35. LatLng sydney = new LatLng(-34, 151);
  36. mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
  37. if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
  38. // TODO: Consider calling
  39. // ActivityCompat#requestPermissions
  40. // here to request the missing permissions, and then overriding
  41. // public void onRequestPermissionsResult(int requestCode, String[] permissions,
  42. // int[] grantResults)
  43. // to handle the case where the user grants the permission. See the documentation
  44. // for ActivityCompat#requestPermissions for more details.
  45. return;
  46. }
  47. mMap.setMyLocationEnabled(true);
  48.  
  49. mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement