1.2.1 • Published 5 years ago

@jonoj/capacitor-fused-location v1.2.1

Weekly downloads
115
License
MIT
Repository
github
Last release
5 years ago

capacitor-fused-location

Description

Geolocation plugin that uses the fused location service instead of the native API.

Getting a location under android is quite difficult. The standard API implemented now in capacitor returns the GPS provider which results in never getting a position indoors. This is not the case under iOS. A better way under Android is the FusedLocationProvider which already handles that.

This plugin currently depends on RxLocation and was initially inspired by this issue/pull request

Supported platforms

  • Android

Android setup

  • ionic start my-cap-app --capacitor
  • cd my-cap-app
  • npm install --save @jonoj/capacitor-fused-location
  • mkdir www && touch www/index.html
  • npx cap add android
  • npx cap sync android
  • npx cap open android
  • [extra step] in android case we need to tell Capacitor to initialise the plugin:

on your MainActivity.java file add import com.jonoj.plugin.FusedLocation; and then inside the init callback add(FusedLocation.class);

Now you should be set to go. Try to run your client using ionic cap run android --livereload.

Tip: every time you change a native code you may need to clean up the cache (Build > Clean Project | Build > Rebuild Project) and then run the app again.

Example

import {FusedLocationPlugin} from '@jonoj/capacitor-fused-location';

const fusedLocation = new FusedLocationPlugin();

class FusedFGeolocationExample {
  async getFusedLocation() {
        if (!(this.platform.is('hybrid') && !this.platform.is('android'))) {
            console.log('only android support!');
            return;
        }
    const coordinates = await fusedLocation.getCurrentPosition();
    console.log('Current', coordinates);
  }

  watchPosition() {
    if (!(this.platform.is('hybrid') && !this.platform.is('android'))) {
        console.log('only android support!');
        return;
    }
    const wait = fusedLocation.watchPosition({}, (position, err) => {
    })
  }
}

Testing

Manually tested against the following platforms:

  • Android emulator 10.0 (API Level 28)
  • Android emulator 7.0 (API Level 24)
  • Android device 6.0 (API Level 23)
1.2.1

5 years ago

1.1.1-b

5 years ago

1.1.1-a

5 years ago

1.1.1

5 years ago

1.0.1

5 years ago

1.0.1-alpha.1

5 years ago

1.0.0

5 years ago

1.0.0-beta.24

5 years ago

1.0.0-beta.19.3

5 years ago

1.0.0-beta.19.2

5 years ago

1.0.0-beta.19.1

5 years ago