Coder Social home page Coder Social logo

alokkulkarni / abc-kmm-location Goto Github PK

View Code? Open in Web Editor NEW

This project forked from line/abc-kmm-location

0.0 0.0 0.0 195 KB

Location Service Manager for Kotlin Multiplatform Mobile iOS and Android

License: Apache License 2.0

Ruby 4.56% Kotlin 95.44%

abc-kmm-location's Introduction

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

  • Super easy to use location capability in one interface
  • Provides simple permission settings and management
  • Dramatically reduce code to write
  • Common interface available on KMM Shared

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()

Installation

Gradle Settings

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

build.gradle.kts in shared

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

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

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

Requirements

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

abc-kmm-location's People

Contributors

pisces avatar rockry avatar hansjin avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.