{"id":82731,"date":"2021-07-20T09:00:41","date_gmt":"2021-07-20T03:30:41","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=82731"},"modified":"2024-08-03T14:56:22","modified_gmt":"2024-08-03T09:26:22","slug":"location-based-services-in-android","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/location-based-services-in-android\/","title":{"rendered":"Location Based Services in Android"},"content":{"rendered":"<p>You must have used apps like <strong>Google Maps, Waze, MapQuest<\/strong>, etc. These are the applications that help you track the location of the device. They also provide services like finding nearby restaurants, hospitals, petrol pumps, etc. Even the cab drivers now use maps to locate their route.<\/p>\n<p>As technology is emerging, it becomes quite essential for an android developer to learn about location-based services. Through this article, you will understand the various sections of location-based services(LBS). After understanding the concepts, you will also see an implementation of the same.<\/p>\n<h3>What are Android Location-Based Services?<\/h3>\n<p>Location-Based Services(LBS) are present in Android to provide you with features like current location detection, display of nearby places, geofencing, etc. It fetches the location using your device\u2019s GPS, Wifi, or Cellular Networks.<\/p>\n<p>To build an app with location-based services, you need to access the Google Play Services Module. After that, you need to use a framework called Location Framework, which has many methods, classes, and interfaces to make your task easier.<\/p>\n<h3>Components of Location-Based Services in Android<\/h3>\n<p>The classes and the interfaces present in the Location Framework acts as the essential components for LBS. Those components are as follows:<\/p>\n<ul>\n<li><strong>LocationManager Class \u2013<\/strong> It is used to get Location Service access from the system.<\/li>\n<li><strong>LocationListener Interface \u2013<\/strong> It receives updates from the Location Manager class.<\/li>\n<li><strong>LocationProvider \u2013<\/strong> It is the class that provides us with the location for our devices.<\/li>\n<li><strong>Location Class \u2013<\/strong> Its objects carry information about the location. The information includes latitude, longitude, accuracy, altitude, and speed.<\/li>\n<\/ul>\n<h3>Location Object<\/h3>\n<p>The location objects carry the location of your device. The place is in the form of latitude and longitude. On the location object, you can apply the below methods. The below methods help you to get location and other information regarding the location.<\/p>\n<h4>1. float distanceTo(Location destination)<\/h4>\n<p>This method calculates and returns the approximate distance in meters between the current location and the specified destination location. It\u2019s useful for navigation and mapping applications to provide distance-based information to users.<\/p>\n<h4>2. float getAccuracy()<\/h4>\n<p>This method returns the accuracy of the current location in meters. A smaller value indicates higher accuracy, helping users understand how precise the location data is, which is particularly important for applications requiring exact positioning.<\/p>\n<h4>3. double getAltitude()<\/h4>\n<p>This method provides the altitude of the current location above sea level in meters. It&#8217;s useful for applications that need to track elevation changes, such as hiking or aviation apps.<\/p>\n<h4>4. double getLatitude()<\/h4>\n<p>This method returns the latitude coordinate of the current location in degrees. Latitude is a geographic coordinate that specifies the north-south position of a point on the Earth&#8217;s surface.<\/p>\n<h4>5. double getLongitude()<\/h4>\n<p>This method returns the longitude coordinate of the current location in degrees. Longitude is a geographic coordinate that specifies the east-west position of a point on the Earth&#8217;s surface.<\/p>\n<h4>6. float getSpeed()<\/h4>\n<p>This method returns the current speed of the device in meters per second. It is useful for applications that track movement, such as fitness apps or vehicle navigation systems.<\/p>\n<h4>7. void setAccuracy(float accuracy)<\/h4>\n<p>Using this method, you can set the desired accuracy level for your location data in meters. This is helpful for simulating different levels of location precision during testing or development.<\/p>\n<h4>8. void setAltitude(double altitude)<\/h4>\n<p>This method allows you to set the altitude of the current location above sea level in meters. It can be used to simulate altitude changes in applications that need to account for elevation.<\/p>\n<h4>9. void setBearing(float bearing)<\/h4>\n<p>This method sets the bearing (direction) of the location in degrees. Bearing is the horizontal direction of travel relative to true north, useful in navigation and tracking applications.<\/p>\n<h4>10. void setLatitude(double Latitude)<\/h4>\n<p>You can set the latitude of your location to a specific value using this method. It\u2019s useful for testing location-based features by simulating movement to different geographic coordinates.<\/p>\n<h4>11. void setLongitude(double longitude)<\/h4>\n<p>You can even set your location to some other longitude using the setLongitude() method.<\/p>\n<h4>12. void setSpeed(float speed)<\/h4>\n<p>This method allows you to set a custom speed for the location, in meters per second. It\u2019s useful for testing applications that monitor or depend on speed data.<\/p>\n<h4>13. void reset()<\/h4>\n<p>This method resets the location to its initial state, clearing any custom settings you\u2019ve applied. It&#8217;s useful for returning to a default state during testing or after simulating specific scenarios.<\/p>\n<h4>14. boolean hasAccuracy()<\/h4>\n<p>This method checks whether the location has an accuracy value set. It returns true if the location data includes accuracy information, which is useful for validating the precision of location data.<\/p>\n<h4>15. boolean hasAltitude()<\/h4>\n<p>This method checks whether the location data includes altitude information. It returns true if the altitude is available, which is important for applications that require elevation data.<\/p>\n<h4>16. boolean hasSpeed()<\/h4>\n<p>This method checks whether the location data includes speed information. It returns true if the speed is available, which is useful for applications that track movement or velocity.<\/p>\n<h4>17. boolean hasBearing()<\/h4>\n<p>This method checks whether the location data includes bearing information. It returns true if the bearing is available, which is essential for navigation and direction-based applications.<\/p>\n<h3>Location Quality of Service<\/h3>\n<p>Quality of Service(QoS) is enabled through the location request object. Location request object requests the proper and accurate location. You can find below the methods that help in the process.<\/p>\n<ul>\n<li><strong>setPriority(int priority) \u2013<\/strong> It allows us to mark the request with priorities. The higher priority request is executed first.<\/li>\n<li><strong>setInterval(long millisecond) \u2013<\/strong> It allows us to set the intervals on which we seek the location updates.<\/li>\n<li><strong>setExpirationDuration(long millisecond) \u2013<\/strong> It allows us to set the duration of the request after which it shall stop.<\/li>\n<li><strong>setExpirationTime(long millisecond) \u2013<\/strong> It allows us to decide the expiration time of our request.<\/li>\n<li><strong>setNumUpdates(int number) \u2013<\/strong> It allows us to set the number of updates we require for a particular place.<\/li>\n<\/ul>\n<h3>Geocoders<\/h3>\n<p>Geocoders are modules present in the Location framework that help convert latitude longitude to human-readable addresses and vice versa.<\/p>\n<p>Usually, an address may come in two formats:<\/p>\n<p>1. Latitude Longitude coordinates of the place.<br \/>\n2. Human readable address of the place.<\/p>\n<p>Now for a device. \u201cChira Chas, Bokaro, Jharkhand, India\u201d is not an understandable address. For us as humans, we can understand the above address. But to make it machine-understandable, we need geocoders. Geocoders will convert the above address to its respective latitude and longitude.<\/p>\n<p>Now for the other scenario, suppose you got an address as \u201c latitude-39.98824 and longitude-134.68742\u201d. Did you understand where it is? Obviously No. So here also geocoders come into the picture. It converts the given latitude and longitude to human-readable addresses.<\/p>\n<p>We can classify the task of geocoder in the following manner:<\/p>\n<h4>1. Forward Geocoding-<\/h4>\n<p>Forward Geocoding implies translation of human-readable addresses to latitude and longitudes.<\/p>\n<h4>2. Reverse Geocoding &#8211;<\/h4>\n<p>Reverse Geocoding implies translation of latitude longitude-based address to human-readable address.<\/p>\n<h3>Get the Last Known Location<\/h3>\n<p>It\u2019s always a better practice to keep track of your last known location. Your system uses your last known location to send you updates based on location. You can get your last known location by calling the getLastLocation() method.<\/p>\n<p>Below is an example of the same.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">private lateinit var fusedLocationClient: FusedLocationProviderClient\r\n\r\noverride fun onCreate(savedInstanceState: Bundle?) {\r\n    \r\n    \/\/Create a Location Client object\r\n    LocationClientObject = LocationServices.getFusedLocationProviderClient(this)\r\n}\r\n<\/pre>\n<p>Now just call the last location method with a listener.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">LocationClientObject.lastLocation\r\n        .addOnSuccessListener { location : Location? -&gt;\r\n            \/\/ you got the location object\r\n            \/\/ the location object has the latitude and longitude of the place.\r\n         \/\/In some cases it may contain null. \r\n        }\r\n\r\n<\/pre>\n<h3>Request Location Update<\/h3>\n<p>To get timely location updates, you can call the requestLocationUpdates() method from the onResume() method of the activity.<\/p>\n<p>Below is an example of the above.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">override fun onResume() {\r\n    super.onResume()\r\n\r\n    \/\/calling the method\r\n\r\n    LocationClientObject.requestLocationUpdates(locationRequest,\r\n            locationCallback,\r\n            Looper.getMainLooper())\r\n}\r\n<\/pre>\n<h3>Implementation of Location-Based Services in Android<\/h3>\n<p>So, after understanding the above concepts. We are ready to implement the concepts through an application. The application will contain a button using which you can get your current location.<\/p>\n<p>Follow the below steps to achieve the goal.<\/p>\n<p><strong>1:<\/strong> Launch your Android Studio.<\/p>\n<p><strong>2:<\/strong> Select Create a New Project.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/Buidling_App_1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-82827\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/Buidling_App_1.png\" alt=\"Create Android Project\" width=\"1184\" height=\"880\" \/><\/a><\/p>\n<p><strong>3:<\/strong> Select Empty Activity and proceed.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/Buidling_App_2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-82828\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/Buidling_App_2.png\" alt=\"Android Activity\" width=\"1332\" height=\"960\" \/><\/a><\/p>\n<p><strong>4:<\/strong> Enter your application name. In my case, it\u2019s \u201cTechVidvanLocation\u201d Next, select Kotlin from the dropdown. For the API level, select API 22 for now.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/Buidling_App_3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-82829\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/Buidling_App_3.png\" alt=\"Android API\" width=\"1360\" height=\"940\" \/><\/a><\/p>\n<p><strong>5:<\/strong> Now, you need to go to your app-level Gradle file and add the google play service dependency. Using the play service, we can access Fused Location Provider.<\/p>\n<p>Paste the below code under your dependencies section.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">implementation 'com.google.android.gms:play-services-location:18.0.0'\r\n<\/pre>\n<p>After pasting the above dependency, sync your project.<\/p>\n<p>Now go to your manifest file and add the permission for internet, fine and coarse location access. You can find the permissions in the below code.<\/p>\n<p><strong>Code: AndroidManifest.xml<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;manifest xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    package=\"com.techvidvan.techvidvanlocation\"&gt;\r\n\r\n    &lt;!--    The required permissions are below     --&gt;\r\n    &lt;uses-permission android:name=\"android.permission.INTERNET\"\/&gt;\r\n    &lt;uses-permission android:name=\"android.permission.ACCESS_FINE_LOCATION\"\/&gt;\r\n    &lt;uses-permission android:name=\"android.permission.ACCESS_COARSE_LOCATION\"\/&gt;\r\n\r\n    &lt;application\r\n        android:allowBackup=\"true\"\r\n        android:icon=\"@mipmap\/ic_launcher\"\r\n        android:label=\"@string\/app_name\"\r\n        android:roundIcon=\"@mipmap\/ic_launcher_round\"\r\n        android:supportsRtl=\"true\"\r\n        android:theme=\"@style\/Theme.TechVidvanLocation\"&gt;\r\n        &lt;activity android:name=\".MainActivity\"&gt;\r\n            &lt;intent-filter&gt;\r\n                &lt;action android:name=\"android.intent.action.MAIN\" \/&gt;\r\n\r\n                &lt;category android:name=\"android.intent.category.LAUNCHER\" \/&gt;\r\n            &lt;\/intent-filter&gt;\r\n        &lt;\/activity&gt;\r\n    &lt;\/application&gt;\r\n\r\n&lt;\/manifest&gt;<\/pre>\n<p><strong>7:<\/strong> Now go to res &#8212;&gt; layout &#8212;-&gt; and open activity_main.xml. Now here, you need to add a button using which you can detect your location. You can paste the below code in your activity_main.xml file.<\/p>\n<p><strong>Code: activity_main.xml<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;androidx.constraintlayout.widget.ConstraintLayout\r\n    xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    xmlns:app=\"http:\/\/schemas.android.com\/apk\/res-auto\"\r\n    xmlns:tools=\"http:\/\/schemas.android.com\/tools\"\r\n    android:layout_width=\"match_parent\"\r\n    android:layout_height=\"match_parent\"\r\n    tools:context=\".MainActivity\"&gt;\r\n\r\n    &lt;TextView\r\n        android:id=\"@+id\/title\"\r\n        android:layout_width=\"wrap_content\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:text=\"TechVidvan Location\"\r\n        app:layout_constraintVertical_bias=\".08\"\r\n        android:textSize=\"28sp\"\r\n        android:textColor=\"#009688\"\r\n        app:layout_constraintBottom_toBottomOf=\"parent\"\r\n        app:layout_constraintLeft_toLeftOf=\"parent\"\r\n        app:layout_constraintRight_toRightOf=\"parent\"\r\n        app:layout_constraintTop_toTopOf=\"parent\" \/&gt;\r\n\r\n    &lt;Button\r\n        android:id=\"@+id\/show_my_location\"\r\n        android:layout_width=\"wrap_content\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:text=\"Show My Location\"\r\n        app:layout_constraintBottom_toBottomOf=\"parent\"\r\n        app:layout_constraintLeft_toLeftOf=\"parent\"\r\n        app:layout_constraintRight_toRightOf=\"parent\"\r\n        app:layout_constraintTop_toTopOf=\"parent\"\r\n        \/&gt;\r\n\r\n&lt;\/androidx.constraintlayout.widget.ConstraintLayout&gt;\r\n<\/pre>\n<p><strong>8:<\/strong> Now, as a final step, you need to edit your MainActivity.kt as follows.<\/p>\n<p><strong>Code: MainActivity.kt<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">package com.techvidvan.techvidvanlocation\r\n\r\nimport android.content.pm.PackageManager\r\nimport androidx.appcompat.app.AppCompatActivity\r\nimport android.os.Bundle\r\nimport android.widget.Button\r\nimport android.widget.Toast\r\nimport androidx.core.app.ActivityCompat\r\nimport com.google.android.gms.location.FusedLocationProviderClient\r\nimport com.google.android.gms.location.LocationServices\r\n\r\nclass MainActivity : AppCompatActivity()\r\n{\r\n    \/\/variable declarations\r\n    lateinit var locationProvideClient:FusedLocationProviderClient\r\n    lateinit var showLocation:Button\r\n\r\n    override fun onCreate(savedInstanceState: Bundle?)\r\n    {\r\n        super.onCreate(savedInstanceState)\r\n        setContentView(R.layout.activity_main)\r\n\r\n        \/\/creating fused location provider object\r\n        locationProvideClient = LocationServices.getFusedLocationProviderClient(this)\r\n\r\n        \/\/binding my button to the variable\r\n        showLocation = findViewById(R.id.show_my_location)\r\n\r\n        \/\/applying onClick Listener on the button\r\n\r\n        showLocation.setOnClickListener{\r\n            \/\/calling the method to fetch your location\r\n            getYourCurrentLocation()\r\n        }\r\n\r\n    }\r\n\r\n    private fun getYourCurrentLocation()\r\n    {\r\n        \/\/Checking if location permissions are provided\r\n        if(ActivityCompat.checkSelfPermission(this,\r\n                android.Manifest.permission.ACCESS_FINE_LOCATION) !=\r\n            PackageManager.PERMISSION_GRANTED &amp;&amp;\r\n            ActivityCompat.checkSelfPermission(this,\r\n                android.Manifest.permission.ACCESS_COARSE_LOCATION) !=\r\n            PackageManager.PERMISSION_GRANTED)\r\n            {\r\n                \/\/Requesting permission to access location\r\n                ActivityCompat.requestPermissions(\r\n                    this,\r\n                    arrayOf(android.Manifest.permission.ACCESS_FINE_LOCATION),\r\n                    909)\r\n                return\r\n        }\r\n\r\n        \/\/fetching your last known location\r\n        val task = locationProvideClient.lastLocation\r\n\r\n        task.addOnSuccessListener {\r\n            if(it!=null)\r\n            {\r\n                \/\/if the fetch is successful, then display the latitude and the longitude\r\n                Toast.makeText(this,\r\n                    \"Latitude : ${it.latitude} \\n Longitude: ${it.longitude}\",\r\n                    Toast.LENGTH_LONG).show()\r\n            }\r\n            else\r\n            {\r\n                Toast.makeText(this,\r\n                    \"Your location can't be displayed\",\r\n                    Toast.LENGTH_LONG).show()\r\n            }\r\n\r\n        }\r\n    }\r\n\r\n\r\n}<\/pre>\n<p>Now, you can test your application.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/App_Output_1-2.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-82830\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/App_Output_1-2.jpg\" alt=\"Android Location based Services\" width=\"1080\" height=\"2280\" \/><\/a><\/p>\n<p>If you have not given the location access, then it will prompt you like below.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/App_Output_2-2.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-82831\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/App_Output_2-2.jpg\" alt=\"Android Location based Service\" width=\"1080\" height=\"2280\" \/><\/a><\/p>\n<p>Now when you allow the location access, then you can get your current location. Just click on the show my location button.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/App_Output_3-2.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-82832\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/App_Output_3-2.jpg\" alt=\"Location Access in Android\" width=\"1080\" height=\"2280\" \/><\/a><\/p>\n<h3>Summary<\/h3>\n<p>So, through this article, we covered a vital topic called Location-Based Services. You very well saw the uses of location-based services and what they mean. Moving further, you saw several components and came across the location object. You got to know geocoders and their uses. Finally, you saw an app implementation of the learned concepts.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You must have used apps like Google Maps, Waze, MapQuest, etc. These are the applications that help you track the location of the device. They also provide services like finding nearby restaurants, hospitals, petrol&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":82826,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2791],"tags":[3808,3809,3810,3811,3812],"class_list":["post-82731","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-android","tag-components-of-location-based-services-in-android","tag-geocoders","tag-implementation-of-location-based-services-in-android","tag-location-based-services-in-android","tag-location-quality-of-service"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Location Based Services in Android - TechVidvan<\/title>\n<meta name=\"description\" content=\"Learn about Location-Based Services in Android and its uses. See its components and location object. Learn about geocoders and their uses.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/location-based-services-in-android\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Location Based Services in Android - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"Learn about Location-Based Services in Android and its uses. See its components and location object. Learn about geocoders and their uses.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/location-based-services-in-android\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-07-20T03:30:41+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-08-03T09:26:22+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/07\/Location-Based-Services-in-Android.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Location Based Services in Android - TechVidvan","description":"Learn about Location-Based Services in Android and its uses. See its components and location object. Learn about geocoders and their uses.","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:\/\/techvidvan.com\/tutorials\/location-based-services-in-android\/","og_locale":"en_US","og_type":"article","og_title":"Location Based Services in Android - TechVidvan","og_description":"Learn about Location-Based Services in Android and its uses. See its components and location object. Learn about geocoders and their uses.","og_url":"https:\/\/techvidvan.com\/tutorials\/location-based-services-in-android\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2021-07-20T03:30:41+00:00","article_modified_time":"2024-08-03T09:26:22+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/07\/Location-Based-Services-in-Android.jpg","type":"image\/jpeg"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/location-based-services-in-android\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/location-based-services-in-android\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"Location Based Services in Android","datePublished":"2021-07-20T03:30:41+00:00","dateModified":"2024-08-03T09:26:22+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/location-based-services-in-android\/"},"wordCount":1537,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/location-based-services-in-android\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/07\/Location-Based-Services-in-Android.jpg","keywords":["Components of Location-Based Services in Android","Geocoders","Implementation of Location-Based Services in Android","Location Based Services in Android","Location Quality of Service"],"articleSection":["Android Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/location-based-services-in-android\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/location-based-services-in-android\/","url":"https:\/\/techvidvan.com\/tutorials\/location-based-services-in-android\/","name":"Location Based Services in Android - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/location-based-services-in-android\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/location-based-services-in-android\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/07\/Location-Based-Services-in-Android.jpg","datePublished":"2021-07-20T03:30:41+00:00","dateModified":"2024-08-03T09:26:22+00:00","description":"Learn about Location-Based Services in Android and its uses. See its components and location object. Learn about geocoders and their uses.","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/location-based-services-in-android\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/location-based-services-in-android\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/location-based-services-in-android\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/07\/Location-Based-Services-in-Android.jpg","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/07\/Location-Based-Services-in-Android.jpg","width":1200,"height":628,"caption":"Location-Based Services in Android"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/location-based-services-in-android\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Location Based Services in Android"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22","name":"TechVidvan Team","description":"The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today\u2019s tech industry."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/82731","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=82731"}],"version-history":[{"count":2,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/82731\/revisions"}],"predecessor-version":[{"id":447577,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/82731\/revisions\/447577"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/82826"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=82731"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=82731"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=82731"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}