{"id":36929,"date":"2024-11-01T09:53:25","date_gmt":"2024-11-01T09:53:25","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=36929"},"modified":"2024-11-01T11:42:58","modified_gmt":"2024-11-01T11:42:58","slug":"building-android-apps-with-kotlin-utilizing-google-maps","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/36929\/","title":{"rendered":"Building Android Apps with Kotlin: Utilizing Google Maps"},"content":{"rendered":"<p>In modern mobile application development, map functionality has become an essential component. Especially for apps that provide location-based services (e.g., food delivery, travel guides, etc.), using Google Maps is very useful. In this tutorial, we will detail how to implement Google Maps in Android apps using Kotlin.<\/p>\n<h2>1. Understanding the Google Maps API<\/h2>\n<p>The Google Maps API is a service that allows developers to integrate Google Maps into their applications. Through this API, various features such as location display, route navigation, and user current location can be utilized.<\/p>\n<h2>2. Setting Up Android Studio Environment<\/h2>\n<p>To integrate Google Maps into your Android app, you first need to set up the development environment. Let&#8217;s start a new project using Android Studio.<\/p>\n<ol>\n<li>Open Android Studio and create a new project.<\/li>\n<li>When creating the project, select <code>Empty Activity<\/code>.<\/li>\n<li>After setting the project name and package name, proceed to the next step.<\/li>\n<\/ol>\n<h2>3. Obtaining the Google Maps API Key<\/h2>\n<p>You need an API key to use Google Maps. Here, I will explain how to obtain the API key.<\/p>\n<ol>\n<li>Visit the Google Cloud Platform and create a new project.<\/li>\n<li>Activate the Maps API in the API &#038; Services menu.<\/li>\n<li>Create an API key, which you will use to send requests.<\/li>\n<li>Add the API key to the <code>res\/values\/strings.xml<\/code> file:<\/li>\n<\/ol>\n<pre><code>&lt;string name=\"google_maps_key\"&gt;YOUR_API_KEY&lt;\/string&gt;<\/code><\/pre>\n<h2>4. Adding Dependencies to Gradle<\/h2>\n<p>You need to add the necessary dependencies to the <code>build.gradle<\/code> file to use Google Maps.<\/p>\n<pre><code>dependencies {\n    implementation 'com.google.android.gms:play-services-maps:17.0.1'\n}\n<\/code><\/pre>\n<h2>5. Creating XML Layout File<\/h2>\n<p>To display the map in the app, you can add a <code>MapView<\/code> or <code>SupportMapFragment<\/code> to the XML layout file. Here, we will use <code>SupportMapFragment<\/code>. Create the <code>res\/layout\/activity_maps.xml<\/code> file as follows:<\/p>\n<pre><code>&lt;RelativeLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"match_parent\"&gt;\n\n    &lt;fragment\n        android:id=\"@+id\/map\"\n        android:name=\"com.google.android.gms.maps.SupportMapFragment\"\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"match_parent\"&gt;\n    &lt;\/fragment&gt;\n\n&lt;\/RelativeLayout&gt;<\/code><\/pre>\n<h2>6. Creating Map Activity<\/h2>\n<p>Now, it&#8217;s time to create an activity to display Google Maps. Create the <code>MapsActivity.kt<\/code> file as follows:<\/p>\n<pre><code>import android.os.Bundle\nimport androidx.appcompat.app.AppCompatActivity\nimport com.google.android.gms.maps.CameraUpdateFactory\nimport com.google.android.gms.maps.GoogleMap\nimport com.google.android.gms.maps.OnMapReadyCallback\nimport com.google.android.gms.maps.SupportMapFragment\nimport com.google.android.gms.maps.model.LatLng\nimport com.google.android.gms.maps.model.MarkerOptions\n\nclass MapsActivity : AppCompatActivity(), OnMapReadyCallback {\n\n    private lateinit var mMap: GoogleMap\n\n    override fun onCreate(savedInstanceState: Bundle?) {\n        super.onCreate(savedInstanceState)\n        setContentView(R.layout.activity_maps)\n\n        \/\/ Obtain the SupportMapFragment and get notified when the map is ready to be used.\n        val mapFragment = supportFragmentManager\n            .findFragmentById(R.id.map) as SupportMapFragment\n        mapFragment.getMapAsync(this)\n    }\n\n    override fun onMapReady(googleMap: GoogleMap) {\n        mMap = googleMap\n\n        \/\/ Add a marker in Sydney and move the camera\n        val sydney = LatLng(-34.0, 151.0)\n        mMap.addMarker(MarkerOptions().position(sydney).title(\"Marker in Sydney\"))\n        mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney))\n    }\n}\n<\/code><\/pre>\n<h2>7. Requesting App Permissions<\/h2>\n<p>To use location information, you need to add the required permissions to the app&#8217;s <code>AndroidManifest.xml<\/code> file:<\/p>\n<pre><code>&lt;uses-permission android:name=\"android.permission.INTERNET\" \/&gt;\n&lt;uses-permission android:name=\"android.permission.ACCESS_FINE_LOCATION\" \/&gt;\n&lt;uses-permission android:name=\"android.permission.ACCESS_COARSE_LOCATION\" \/&gt;\n\n&lt;application\n    ... &gt;\n    &lt;meta-data\n        android:name=\"com.google.android.geo.API_KEY\"\n        android:value=\"@string\/google_maps_key\" \/&gt;\n&lt;\/application&gt;<\/code><\/pre>\n<h2>8. Displaying Current Location on Map<\/h2>\n<p>Let&#8217;s add functionality to display the current location on the app. Add the code to enable user location in the <code>onMapReady<\/code> method:<\/p>\n<pre><code>if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &amp;&amp; ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {\n    \/\/ If permission is not granted\n    ActivityCompat.requestPermissions(this, arrayOf(android.Manifest.permission.ACCESS_FINE_LOCATION), 1000)\n    return\n}\nmMap.isMyLocationEnabled = true\n<\/code><\/pre>\n<h2>9. Pinpointing User Location<\/h2>\n<p>In addition to adding the basic location, you can implement functionality to pin a specific location when the user selects it. Add the following code to the <code>onMapClickListener<\/code> method:<\/p>\n<pre><code>mMap.setOnMapClickListener { latLng -&gt;\n    mMap.addMarker(MarkerOptions().position(latLng).title(\"Selected Location\"))\n}\n<\/code><\/pre>\n<h2>10. Additional API Features<\/h2>\n<p>The Google Maps API provides various features beyond simple map display. For example, drawing routes, adding multiple markers, or creating custom markers. Below is an example of creating a custom marker:<\/p>\n<pre><code>val bitmap = BitmapFactory.decodeResource(resources, R.drawable.custom_marker)\nval markerOptions = MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromBitmap(bitmap))\nmMap.addMarker(markerOptions)\n<\/code><\/pre>\n<h2>11. Testing and Deployment<\/h2>\n<p>Once the app is complete, you can test it on an emulator or a real device. After ensuring there are no issues, you will prepare it for distribution on the Play Store. To distribute, create an APK file and upload it via the Play Console.<\/p>\n<h2>Conclusion<\/h2>\n<p>In this tutorial, we learned how to utilize Google Maps in Android apps using Kotlin. The Google Maps API offers various and powerful features, so take advantage of it to develop location-based services. Through various examples and exercises, we hope you become a better developer.<\/p>\n<p>If you found this tutorial helpful, please share it and leave a comment! We are preparing a series of more Android development tutorials, so stay tuned.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In modern mobile application development, map functionality has become an essential component. Especially for apps that provide location-based services (e.g., food delivery, travel guides, etc.), using Google Maps is very useful. In this tutorial, we will detail how to implement Google Maps in Android apps using Kotlin. 1. Understanding the Google Maps API The Google &hellip; <a href=\"https:\/\/atmokpo.com\/w\/36929\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Building Android Apps with Kotlin: Utilizing Google Maps&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[143],"tags":[],"class_list":["post-36929","post","type-post","status-publish","format-standard","hentry","category-kotlin-android-app-development"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Building Android Apps with Kotlin: Utilizing Google Maps - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/atmokpo.com\/w\/36929\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Building Android Apps with Kotlin: Utilizing Google Maps - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"In modern mobile application development, map functionality has become an essential component. Especially for apps that provide location-based services (e.g., food delivery, travel guides, etc.), using Google Maps is very useful. In this tutorial, we will detail how to implement Google Maps in Android apps using Kotlin. 1. Understanding the Google Maps API The Google &hellip; \ub354 \ubcf4\uae30 &quot;Building Android Apps with Kotlin: Utilizing Google Maps&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/36929\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:53:25+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:42:58+00:00\" \/>\n<meta name=\"author\" content=\"root\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:site\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:label1\" content=\"\uae00\uc4f4\uc774\" \/>\n\t<meta name=\"twitter:data1\" content=\"root\" \/>\n\t<meta name=\"twitter:label2\" content=\"\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04\" \/>\n\t<meta name=\"twitter:data2\" content=\"4\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/36929\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/36929\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Building Android Apps with Kotlin: Utilizing Google Maps\",\"datePublished\":\"2024-11-01T09:53:25+00:00\",\"dateModified\":\"2024-11-01T11:42:58+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/36929\/\"},\"wordCount\":514,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Kotlin Android app development\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/36929\/\",\"url\":\"https:\/\/atmokpo.com\/w\/36929\/\",\"name\":\"Building Android Apps with Kotlin: Utilizing Google Maps - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:53:25+00:00\",\"dateModified\":\"2024-11-01T11:42:58+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/36929\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/36929\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/36929\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Building Android Apps with Kotlin: Utilizing Google Maps\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/atmokpo.com\/w\/#website\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/atmokpo.com\/w\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ko-KR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"contentUrl\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"width\":400,\"height\":400,\"caption\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\"},\"image\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/bebubo4\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\",\"name\":\"root\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"caption\":\"root\"},\"sameAs\":[\"http:\/\/atmokpo.com\/w\"],\"url\":\"https:\/\/atmokpo.com\/w\/author\/root\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Building Android Apps with Kotlin: Utilizing Google Maps - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/atmokpo.com\/w\/36929\/","og_locale":"ko_KR","og_type":"article","og_title":"Building Android Apps with Kotlin: Utilizing Google Maps - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"In modern mobile application development, map functionality has become an essential component. Especially for apps that provide location-based services (e.g., food delivery, travel guides, etc.), using Google Maps is very useful. In this tutorial, we will detail how to implement Google Maps in Android apps using Kotlin. 1. Understanding the Google Maps API The Google &hellip; \ub354 \ubcf4\uae30 \"Building Android Apps with Kotlin: Utilizing Google Maps\"","og_url":"https:\/\/atmokpo.com\/w\/36929\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:53:25+00:00","article_modified_time":"2024-11-01T11:42:58+00:00","author":"root","twitter_card":"summary_large_image","twitter_creator":"@bebubo4","twitter_site":"@bebubo4","twitter_misc":{"\uae00\uc4f4\uc774":"root","\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04":"4\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/36929\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/36929\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Building Android Apps with Kotlin: Utilizing Google Maps","datePublished":"2024-11-01T09:53:25+00:00","dateModified":"2024-11-01T11:42:58+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/36929\/"},"wordCount":514,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Kotlin Android app development"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/36929\/","url":"https:\/\/atmokpo.com\/w\/36929\/","name":"Building Android Apps with Kotlin: Utilizing Google Maps - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:53:25+00:00","dateModified":"2024-11-01T11:42:58+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/36929\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/36929\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/36929\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Building Android Apps with Kotlin: Utilizing Google Maps"}]},{"@type":"WebSite","@id":"https:\/\/atmokpo.com\/w\/#website","url":"https:\/\/atmokpo.com\/w\/","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","description":"","publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/atmokpo.com\/w\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ko-KR"},{"@type":"Organization","@id":"https:\/\/atmokpo.com\/w\/#organization","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","url":"https:\/\/atmokpo.com\/w\/","logo":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/","url":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","contentUrl":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","width":400,"height":400,"caption":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8"},"image":{"@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/bebubo4"]},{"@type":"Person","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7","name":"root","image":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","caption":"root"},"sameAs":["http:\/\/atmokpo.com\/w"],"url":"https:\/\/atmokpo.com\/w\/author\/root\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/36929","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/comments?post=36929"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/36929\/revisions"}],"predecessor-version":[{"id":36930,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/36929\/revisions\/36930"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=36929"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=36929"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=36929"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}