项目作者: icerockdev

项目描述 :
Geolocation access for mobile (android & ios) Kotlin Multiplatform development
高级语言: Kotlin
项目地址: git://github.com/icerockdev/moko-geo.git
创建时间: 2019-12-23T05:30:25Z
项目社区:https://github.com/icerockdev/moko-geo

开源协议:Apache License 2.0

下载


moko-mvvm
GitHub license Download kotlin-version

Mobile Kotlin geolocation module

This is a Kotlin Multiplatform library that provides geolocation to common code.

Table of Contents

Features

  • Geolocation tracking - track user geolocation from common code;
  • Compose Multiplatform support;

Requirements

  • Gradle version 6.0+
  • Android API 16+
  • iOS version 9.0+

Installation

root build.gradle

  1. allprojects {
  2. repositories {
  3. mavenCentral()
  4. }
  5. }

project build.gradle

  1. dependencies {
  2. commonMainApi("dev.icerock.moko:geo:0.8.0")
  3. // Compose Multiplatform
  4. commonMainApi("dev.icerock.moko:geo-compose:0.8.0")
  5. }

Usage

in common code:

  1. class TrackerViewModel(
  2. val locationTracker: LocationTracker
  3. ) : ViewModel() {
  4. init {
  5. viewModelScope.launch {
  6. locationTracker.getLocationsFlow()
  7. .distinctUntilChanged()
  8. .collect { println("new location: $it") }
  9. }
  10. }
  11. fun onStartPressed() {
  12. viewModelScope.launch { locationTracker.startTracking() }
  13. }
  14. fun onStopPressed() {
  15. locationTracker.stopTracking()
  16. }
  17. }

In Android:

  1. // create ViewModel
  2. val locationTracker = LocationTracker(
  3. permissionsController = PermissionsController(applicationContext = applicationContext)
  4. )
  5. val viewModel = TrackerViewModel(locationTracker)
  6. // bind tracker to lifecycle
  7. viewModel.locationTracker.bind(lifecycle, this, supportFragmentManager)

In iOS:

  1. let viewModel = TrackerViewModel(
  2. locationTracker: LocationTracker(
  3. permissionsController: PermissionsController(),
  4. accuracy: kCLLocationAccuracyBest
  5. )
  6. )

Samples

Please see more examples in the sample directory.

Set Up Locally

  • The geo directory contains the geo library;
  • In sample directory contains sample apps for Android and iOS; plus the mpp-library connected to the apps.

Contributing

All development (both new features and bug fixes) is performed in the develop branch. This way master always contains the sources of the most recently released version. Please send PRs with bug fixes to the develop branch. Documentation fixes in the markdown files are an exception to this rule. They are updated directly in master.

The develop branch is pushed to master on release.

For more details on contributing please see the contributing guide.

Before send PR please run checks on local:

  • ./local-check.sh in root of repository
  • ./local-check.sh in sample directory

License

  1. Copyright 2019 IceRock MAG Inc.
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.