/react-native-device-country

Get device location by telephony (SIM card) or settings without using GPS tracker.

Primary LanguageJavaMIT LicenseMIT

react-native-device-country

Get device location by telephony (SIM card) or settings without using GPS tracker

npm version npm MIT
Platform - Android Platform - iOS

Installation

yarn add react-native-device-country

or

npm install react-native-device-country

Don't forget to run pod install after that!

Usage

import DeviceCountry, {
  TYPE_ANY,
  TYPE_TELEPHONY,
  TYPE_CONFIGURATION,
} from 'react-native-device-country';

// ...

DeviceCountry.getCountryCode()
  .then((result) => {
    console.log(result);
    // {"code": "BY", "type": "telephony"}
  })
  .catch((e) => {
    console.log(e);
  });

You can use spicific method for getting country

TYPE_TELEPHONY for getting country code from SIM card

DeviceCountry.getCountryCode(TYPE_TELEPHONY)
  .then((result) => {
    console.log(result);
    // {"code": "BY", "type": "telephony"}
  })
  .catch((e) => {
    console.log(e);
  });

or TYPE_CONFIGURATION for getting country code from phone location settings on iOS and phone language settings on Android

DeviceCountry.getCountryCode(TYPE_CONFIGURATION)
  .then((result) => {
    console.log(result);
    // {"code": "BY", "type": "config"}
  })
  .catch((e) => {
    console.log(e);
  });

TYPE_ANY will be used by default. It tries to use TYPE_TELEPHONY and fallbacks with TYPE_CONFIGURATION, if devive without SIM card.

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT