Skip to content

faramarzaf/Bootcamp-Map

Repository files navigation

Bootcamp-Map

Step 1. Open Google developer console and signin with your gmail account: https://console.developers.google.com/project

Step 2. Now create new project. You can create new project by clicking on the Create Project button and give name to your project.

Step 3. Now click on APIs & Services and open Dashboard from it.

Step 4. Open Enable APIS AND SERICES.

Step 5. Now open Google Map Android API.

Step 6. Now enable the Google Maps Android API.

Step 7. Now go to Credentials.

Step 8. Here click on Create credentials and choose API key.

Step 9. Now API your API key will be generated. Copy it and save it somewhere as we will need it when implementing Google Map in our Android project.

Now paste API key here:

Display a map, using the Maps SDK for Android

Add a <fragment> element to your activity's layout file, activity_maps.xml. This element defines a SupportMapFragment to act as a container for the map and to provide access to the GoogleMap object.

 <fragment xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
     android:id="@+id/map"
     android:name="com.google.android.gms.maps.SupportMapFragment"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     tools:context="com.example.mapwithmarker.MapsMarkerActivity" />

In your activity's onCreate() method, set the layout file as the content view.

Get a handle to the map fragment by calling FragmentManager.findFragmentById(). Then use getMapAsync() to register for the map callback.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Retrieve the content view that renders the map.
    setContentView(R.layout.activity_maps);
    // Get the SupportMapFragment and request notification
    // when the map is ready to be used.
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
}

Implement the OnMapReadyCallback interface and override the onMapReady() method, to set up the map when the GoogleMap object is available.

public class MapsMarkerActivity extends AppCompatActivity
        implements OnMapReadyCallback {
    // Include the OnCreate() method here too, as described above.
    @Override
    public void onMapReady(GoogleMap googleMap) {
        // Add a marker in Sydney, Australia,
        // and move the map's camera to the same location.
        LatLng sydney = new LatLng(-33.852, 151.211);
        googleMap.addMarker(new MarkerOptions().position(sydney)
                .title("Marker in Sydney"));
        googleMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
    }
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages