yudaduy

Untitled

Apr 28th, 2021
884
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.50 KB | None | 0 0
  1. // Copyright 2020 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. //      http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14.  
  15. package com.google.maps.example;
  16.  
  17.  
  18. import androidx.appcompat.app.AppCompatActivity;
  19.  
  20. import android.os.Bundle;
  21.  
  22. import com.google.android.gms.maps.CameraUpdateFactory;
  23. import com.google.android.gms.maps.GoogleMap;
  24. import com.google.android.gms.maps.OnMapReadyCallback;
  25. import com.google.android.gms.maps.SupportMapFragment;
  26. import com.google.android.gms.maps.model.LatLng;
  27. import com.google.android.gms.maps.model.MarkerOptions;
  28.  
  29. public class MapsActivity extends AppCompatActivity implements OnMapReadyCallback {
  30.  
  31.     private GoogleMap mMap;
  32.  
  33.     @Override
  34.     protected void onCreate(Bundle savedInstanceState) {
  35.         super.onCreate(savedInstanceState);
  36.         setContentView(R.layout.activity_maps);
  37.         // Obtain the SupportMapFragment and get notified when the map is ready to be used.
  38.         SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
  39.                 .findFragmentById(R.id.map);
  40.         mapFragment.getMapAsync(this);
  41.     }
  42.  
  43.     /**
  44.      * Manipulates the map once available.
  45.      * This callback is triggered when the map is ready to be used.
  46.      * This is where we can add markers or lines, add listeners or move the camera. In this case,
  47.      * we just add a marker near Sydney, Australia.
  48.      *
  49.      * If Google Play services is not installed on the device, the user will be prompted to install
  50.      * it inside the SupportMapFragment. This method will only be triggered once the user has
  51.      * installed Google Play services and returned to the app.
  52.      */
  53.     @Override
  54.     public void onMapReady(GoogleMap googleMap) {
  55.         mMap = googleMap;
  56.  
  57.         // Add a marker in Sydney and move the camera
  58.         LatLng sydney = new LatLng(-34, 151);
  59.         mMap.addMarker(new MarkerOptions()
  60.                 .position(sydney)
  61.                 .title("Marker in Sydney"));
  62.         mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment