Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get user country without gps

In react native i am trying to get user country without using the users gps, just like Wechat registration which automatically gets the users country in the picker(select) field.

like image 801
Starbody Avatar asked Dec 23 '22 02:12

Starbody


1 Answers

it can be done by two ways

  1. get the IP address of user but it works only with internet connection

  2. the best way is to get the local country of the device itself with the use of react-native-device-info

const deviceCountry = DeviceInfo.getDeviceCountry(); // "US", "IN"

ref: react-native-device-info#getdevicecountry

like image 66
Jigar Avatar answered Dec 25 '22 22:12

Jigar