Customizing the code

The default code generated shows the market in Sydney. The method onMapReady shown here gets called when the map is ready and loaded and displays a marker. The location is found based on the LatLng value mentioned:

override fun onMapReady(googleMap: GoogleMap) {
mMap = googleMap
// Add a marker in Sydney and move the camera
val sydney= LatLng(-33.852,151.211)
mMap.addMarker(MarkerOptions().position(sydney).title("Marker in Sydney"))
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney))
}

Let's now customize this code to display the marker over Chennai, Tamil Nadu, India. To make the change, the first step is to understand what Lat and Lng stand for.

Latitude and longitude are used together to specify the precise location of any part of the earth. In Android, the class LatLng is used for specifying the location.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset