Book Image

Learning Kotlin by building Android Applications

By : Eunice Adutwumwaa Obugyei, Natarajan Raman
Book Image

Learning Kotlin by building Android Applications

By: Eunice Adutwumwaa Obugyei, Natarajan Raman

Overview of this book

<p>Today Kotlin is an official programming language for Android development and is widely adopted. Kotlin is expressive, concise, and powerful. It also ensures seamless interoperability with existing Android languages like JAVA and C++, which means that it's even easier for developers to use.</p> <p>This book adopts a project-style approach, where we focus on teaching Android development by building three different Android Application: a Tic-Tac-Toe application, a location- based alarm and a To-Do list application.</p> <p>The book begins by giving you a strong grasp of the Kotlin language and its APIs as a preliminary to building stunning applications for Android. You'll learn to set up an environment and as you progress through the chapters and the building of the different applications, the difficulty level will steadily grow.</p> <p>The book also introduces you to the Android Studio IDE, which plays an integral role in Android Development. It covers Kotlin's basic programming concepts such as functions, lambdas, properties, object-oriented code, safety aspects and type parameterization, testing, and concurrency, and helps you write Kotlin code to production.</p> <p>Finally, you'll be taken through the process of releasing your app on the Google Play Store. You will also be introduced to other app distribution channels such as Amazon App Store.</p> <p>As a bonus chapter, you will also learn how to use the Google Faces API to detect faces and add fun functionalities.</p>
Table of Contents (21 chapters)
Title Page
Packt Upsell
Contributors
Preface
Index

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.

Finding the Lat and Lng of a place

Finding the latitude and longitude of a place can be done easily using Google Maps in the browser. For our purpose, we will launch...