Software Engineering

Default Google Map Activity for Android

This Activity code will provide basic functionality for including a Google Map using a SupportMapFragment.

The Google Maps V2 API includes an all-new way to load maps.

Activities now have to implement the OnMapReadyCallBack interface, which comes with a onMapReady() method override that is executed every time we run SupportMapFragment.getMapAsync(OnMapReadyCallback); and the call is successfully completed.
Maps use Markers, Polygons and PolyLines to show interactive information to the user.

MapsActivity.java:

public class MapsActivity extends AppCompatActivity implements OnMapReadyCallback { 
   private GoogleMap mMap;
   @Override
   protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.activity_maps);
     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.newLatLng(sydney));
 } 
}

Notice that the code above inflates a layout, which has a SupportMapFragment nested inside the container Layout, defined with an ID of R.id.map. The layout file is shown below:

activity_maps.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent">
  <fragment 
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools" 
  xmlns:map="http://schemas.android.com/apk/res-auto" 
            android:layout_width="match_parent" 
            android:layout_height="match_parent"
            android:id="@+id/map" 
            tools:context="com.example.app.MapsActivity"
            android:name="com.google.android.gms.maps.SupportMapFragment"/>
</LinearLayout>

This is the Basic Google Map integration

Shibaji Debnath

Recent Posts

Is a full-stack developer course suitable for you?

A full-stack developer course is good or not. This time, so many people want to…

5 months ago

Setting up a Developer Workspace: Tips for setting up a comfortable and productive coding environment

As a software developer, having a comfortable and productive coding environment is essential to your…

7 months ago

Top 5 Software Development Career Options

Discovering the Software Development Career: This article will teach you everything you need to know…

8 months ago

How to Start Learning about Software Programming

Software Programming is done with various software programming languages. We are using these languages used…

2 years ago

How can start AI Application development with JavaScript?

There are several ways to AI application development using JavaScript, depending on your goals and…

2 years ago

Streaming Audio Player app develop by Angular

This is the angular live project on audio player for website and mobile. This app…

5 years ago

This website uses cookies.