0% found this document useful (0 votes)
3 views

Map API Code

The document outlines the steps to integrate Google Maps into an Android application. It includes the necessary configurations in AndroidManifest.xml, build.gradle.kts, and activity_main.xml, as well as the implementation of a MainActivity class that initializes the map and adds a marker in Sydney. The provided code snippets demonstrate how to set up the map and handle its readiness using the OnMapReadyCallback interface.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Map API Code

The document outlines the steps to integrate Google Maps into an Android application. It includes the necessary configurations in AndroidManifest.xml, build.gradle.kts, and activity_main.xml, as well as the implementation of a MainActivity class that initializes the map and adds a marker in Sydney. The provided code snippets demonstrate how to set up the map and handle its readiness using the OnMapReadyCallback interface.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

1) AndroidManifest.

xml (Inside application Tag)

<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="API KEY" />

2) build.gradle.kts(Module :App) (inside dependancies)

implementation("com.google.android.gms:play-services-maps:18.2.0")

3) activity_main.xml

<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

4) MainActivity.java

public class MainActivity extends AppCompatActivity implements OnMapReadyCallback {

private GoogleMap mMap;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// Get the SupportMapFragment and request notification when the map is


ready
SupportMapFragment mapFragment = (SupportMapFragment)
getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}

@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in Sydney, Australia, and move the camera
LatLng sydney = new LatLng(-34, 151);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in
Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(sydney, 12));
}
}

You might also like