react-native-gps icon indicating copy to clipboard operation
react-native-gps copied to clipboard

add RNLocation.endUpdatingLocation() method request

Open arcollector opened this issue 7 years ago • 3 comments

Hi, is there any odds to add the ability to stop listening the gps, thanks!

arcollector avatar Dec 03 '17 23:12 arcollector

Hi @arcollector , when you use Location.stopUpdatingLocation(); still listening the gps?

agrass avatar Dec 12 '17 13:12 agrass

oups, i didnt know that the method is called RNLocation.stopUpdatingLocation() now my problem is that the map-marker icon is displaying in the status top bar (in android) regardless of previously calling this function

arcollector avatar Dec 13 '17 21:12 arcollector

i found the solution to remove the map marker icon from the status bar, I need to save a reference from DeviceEventEmitter output and then call remove method from it, I only tested on android

import {
  DeviceEventEmitter,
  NativeModules,
} from 'react-native';

import type EmitterSubscription from 'EmitterSubscription';

type coordinates = {| latitude: number, longitude: number |};

export default class GPS {
  eventEmitter: EmitterSubscription | null = null

  init = (): void => {
    const { RNLocation } = NativeModules;
    RNLocation.startUpdatingLocation();
    this.eventEmitter = DeviceEventEmitter.addListener(
      'locationUpdated',
      (position: coordinates): void => {
        console.log('RNLocation', position);
        this.onLocation(position);
      }
    );
  }

  uninit = (): void {
    const { RNLocation } = NativeModules;
    RNLocation.stopUpdatingLocation();
    this.eventEmitter && this.eventEmitter.remove();
  }
}

arcollector avatar Dec 15 '17 03:12 arcollector