As a Native android developer, it is very difficult to parse a complex JSON in our application. Normally the rest api json structure is much complex to parse it using functions as getObject(), getString(), getBoolean() etc. So, In order to overcome this problem also for save time we use GSON. Many developers already know that, but here I give you a simple and short solution that, you can convert JSON to Kotlin Model class for any complex JSON within 5 seconds. So Just follow the guidelines- Okay, First you can add the gradle dependency of GSON implementation 'com.google.code.gson:gson:2.8.6' Now I can take a sample JSON, which I make model class and then parse. Below I mentioned the sample json- { "problems" : [ { "Diabetes" : [ { "medications" : [ { "medicationsClasses" : [ { "className" : [ { ...
How to fetch Latitude, Longitude from address and vice-versa(address from Latitude, Longitude) using Google Geo coder SDK in android| Kotlin
In this Android development related article, you will get a simple solution that, how to get address using Latitude, Longitude and vice-versa. i.e latitude, longitude from an address text. It is very easy and simple. Read full article and carefully follow all the steps. Here we use google Geocoder SDK. Okay, first we create an android project in kotlin and create an Activity say MainActivity.kt. Use the below code- Function get Latitude, Longitude from Address- fun getLatLngFromAddress (context: Context, mAddress: String): String { val coder = Geocoder(context) lateinit var address: List<Address> try { address = coder.getFromLocationName(mAddress, 5 ) if (address == null ) { return "Fail to find Lat,Lng" } val location = address[ 0 ] return " Latitude: ${location.latitude}\n Longitude: ${location.longitude}" } catch (e: Exception...