Location Service Manager for Kotlin Multiplatform Mobile iOS and android

Overview

abc-kmm-location: Location Service Manager for Kotlin Multiplatform Mobile iOS and android

Kotlin KMM AGP Gradle Platform

Location Service Manager for Kotlin Multiplatform Mobile iOS and android

Features

  • Provides simple permission settings
  • Dramatically reduce the amount of code
  • Common interface available on KMM Shared

Requirements

  • iOS
    • Deployment Target 10.0 or higher
  • Android
    • minSdkVersion 21

Installation

Gradle Settings

Add below gradle settings into your KMP (Kotlin Multiplatform Project)

build.gradle.kts in root

buildscript {
    repositories {
        gradlePluginPortal()
        google()
        mavenCentral()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:7.0.1")
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.21")
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
        maven {
            url = uri("http://repo.navercorp.com/maven-release/")
            isAllowInsecureProtocol = true
        }
        maven {
            url = uri("http://repo.navercorp.com/maven-snapshot/")
            isAllowInsecureProtocol = true
        }
    }
}

build.gradle.kts in shared

plugins {
    id("com.android.library")
    kotlin("multiplatform")
    kotlin("native.cocoapods")
}

val abcLocationLib = "com.linecorp:abc-kmm-location:0.2.3"

kotlin {
    android()
    ios {
        binaries
            .filterIsInstance<Framework>()
            .forEach {
                it.baseName = "shared"
                it.transitiveExport = true
                it.export(abcLocationLib)
            }
    }

    sourceSets {
        val commonMain by getting {
            dependencies {
                implementation(abcLocationLib)
            }
        }
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test-common"))
                implementation(kotlin("test-annotations-common"))
            }
        }
        val androidMain by getting {
            dependencies {
                implementation("com.google.android.material:material:1.2.1")
                implementation(abcLocationLib)
            }
        }
        val androidTest by getting {
            dependencies {
                implementation(kotlin("test-junit"))
                implementation("junit:junit:4.13.2")
                implementation("androidx.test:core:1.0.0")
                implementation("androidx.test:runner:1.1.0")
                implementation("org.robolectric:robolectric:4.2")
            }
        }
        val iosMain by getting {
            dependencies {
                implementation(abcLocationLib)
            }
        }
        val iosTest by getting
    }
}

Project Settings

Android

  • You can use right now without other settings.

iOS

  1. Create Podfile with below setting in your project root.
use_frameworks!

platform :ios, '10.0'

install! 'cocoapods', :deterministic_uuids => false

target 'iosApp' do
    pod 'shared', :path => '../shared/'
end
  1. Run command pod install on the terminal

Usage

Register handlers for permissions

  • Android

    ABCLocation
        .onPermissionUpdated(this) { isGranted ->
            println("onPermissionUpdated -> isGranted: $isGranted")
        }
        .onLocationUnavailable(this) {
            println("onLocationUnavailable")
        }
  • iOS

    ABCLocation.Companion()
        .onPermissionUpdated(target: self) { isGranted ->
            print("onPermissionUpdated -> isGranted: \(isGranted)")
        }
        .onLocationUnavailable(target: self) {
            print("onLocationUnavailable")
        }
        .onAlwaysAllowsPermissionRequired(target: self) {
            print("onAlwaysAllowsPermissionRequired")
        }

To get current location just once

  • Android

    ABCLocation.currentLocation { data ->
        println("currentLocation -> data: $data")
    }
  • iOS

    ABCLocation.Companion().currentLocation { data in
        print("currentLocation -> data: \(data)")
    }

To get current location whenever location changes

  • Android

    ABCLocation
        .onLocationUpdated(this) { data ->
            println("onLocationUpdated -> data: $data")
        }
        .startLocationUpdating()
  • iOS

    ABCLocation.Companion()
        .onLocationUpdated(target: self) { data in
            print("onLocationUpdated -> data: \(data)")
        }
        .startLocationUpdating()

To stop location updating

  • Android

    ABCLocation.stopLocationUpdating()
  • iOS

    ABCLocation.Companion().stopLocationUpdating()
You might also like...
Crypto-candlestick-service - Crypto candlestick service Coding Challenge
Crypto-candlestick-service - Crypto candlestick service Coding Challenge

Coding Challenge Your task is to build a system that enables users to view price

KMM RSS Reader: an open-source, mobile, cross-platform application built with Kotlin Multiplatform Mobile.
KMM RSS Reader: an open-source, mobile, cross-platform application built with Kotlin Multiplatform Mobile.

KMM RSS Reader This is an open-source, mobile, cross-platform application built with Kotlin Multiplatform Mobile. It's a simple RSS reader, and you ca

Link-converter - A web service that converts links between web url and deeplink for mobile and web applications

Deep Link Converter Linkleri, mobil ve web uygulamaları için web url ile deeplin

Real life Kotlin Multiplatform project with an iOS application developed in Swift with SwiftUI, an Android application developed in Kotlin with Jetpack Compose and a backed in Kotlin hosted on AppEngine.

Conferences4Hall Real life Kotlin Multiplatform project with an iOS application developed in Swift with SwiftUI, an Android application developed in K

A Bluetooth kotlin multiplatform "Cross-Platform" library for iOS and Android

Blue-Falcon A Bluetooth "Cross Platform" Kotlin Multiplatform library for iOS, Android, MacOS, Raspberry Pi and Javascript. Bluetooth in general has t

Dependency Injection library for Kotlin Multiplatform, support iOS and Android

Multiplatform-DI library for Kotlin Multiplatform Lightweight dependency injection framework for Kotlin Multiplatform application Dependency injection

Simple Kotlin Multiplatform PrayerTimes App for iOS and Android

Kotlin Multiplatform ___ _______ ___ / _ \_______ ___ _____ ___/_ __(_)_ _ ___ ___ / _ | __

A Kotlin Multiplatform Project using TMDB Api. Currently supports Android,iOS,Desktop and web platforms
A Kotlin Multiplatform Project using TMDB Api. Currently supports Android,iOS,Desktop and web platforms

A Kotlin Multiplatform Project using TMDB Api(https://www.themoviedb.org/). Currently this project is implemented in following platforms Andr

BlurHash support for iOS, Android and JVM via Kotlin Multiplatform
BlurHash support for iOS, Android and JVM via Kotlin Multiplatform

blurhash A Kotlin Multiplatform library to use blurhash in your Android App, iOS / Mac App & JVM Backend. Android iOS JVM Why? If you've tried using b

Releases(0.2.9)
Owner
LINE
LINE
An Awesome Kotlin Location library to retrieve location merely in 3 lines of code

An Awesome Kotlin Location library to retrieve location merely in 3 lines of code

Birju Vachhani 288 Dec 30, 2022
Location-permission-handler - Location Permission Handler For Android

Location Permission Handler Easy way to check location permissions for Android 9

null 1 Feb 1, 2022
Location-history-viewer - Small compose-desktop app to view data from google's location history

Google Location History Takeout Viewer This application provides a minimalistic

Chris Stelzmüller 3 Jun 23, 2022
An app architecture for Kotlin/Native on Android/iOS. Use Kotlin Multiplatform Mobile.

An app architecture for Kotlin/Native on Android/iOS. Use Kotlin Multiplatform Mobile. 项目架构主要分为原生系统层、Android/iOS业务SDK层、KMM SDK层、KMM业务逻辑SDK层、iOS sdkfra

libill 4 Nov 20, 2022
Kotlin Multiplatform Mobile demo for Android and iOS - app for viewing Cat pictures

CatViewerDemo Android demo iOS demo Kotlin Multiplatform Mobile demo for Android and iOS. App for viewing Cat pictures from Cats API. This sample show

Martin Rajniak 111 Dec 18, 2022
A local storage management library for Kotlin Multiplatform Mobile iOS and android

A local storage management library for Kotlin Multiplatform Mobile iOS and android Features iOS and Android local storage in one interface Provides ge

LINE 20 Oct 30, 2022
Kotlin Multiplatform is an SDK for cross-platform mobile development, which enables teams to use the same business logic in both Android and iOS client applications.

Kotlin Multiplatform is an SDK for cross-platform mobile development, which enables teams to use the same business logic in both Android and iOS client applications.

Chris Russell 1 Feb 11, 2022
Ethereum Web3 implementation for mobile (android & ios) Kotlin Multiplatform development

Mobile Kotlin web3 This is a Kotlin MultiPlatform library that ... Table of Contents Features Requirements Installation Usage Samples Set Up Locally C

IceRock Development 32 Aug 26, 2022
🍭 GithubSearchKMM - Github Repos Search - Android - iOS - Kotlin Multiplatform Mobile using Jetpack Compose, SwiftUI, FlowRedux, Coroutines Flow, Dagger Hilt, Koin Dependency Injection, shared KMP ViewModel, Clean Architecture

GithubSearchKMM Github Repos Search - Kotlin Multiplatform Mobile using Jetpack Compose, SwiftUI, FlowRedux, Coroutines Flow, Dagger Hilt, Koin Depend

Petrus Nguyễn Thái Học 50 Jan 7, 2023
Kotlin Multiplatform Mobile + Mobile Declarative UI Framework (Jetpack Compose and SwiftUI)

Kotlin Multiplatform Mobile + Mobile Declarative UI Framework (Jetpack Compose and SwiftUI)

Kotchaphan Muangsan 3 Nov 15, 2022