DEV Community

Discussion on: Not just another Coronavirus (covid-19) dashboard with live statistics

Collapse
 
chan_austria777 profile image
chan 🤖

there's a widget that defaults to the current country of the viewer. Would you mind sharing how to do that?

Collapse
 
otomer profile image
Tomer Ovadia

Hi @chan_austria777 , sure! I am basing my decision of what country to auto-select according to the client's public IP address. Note that it's not 100% correct since you might be using a VPN or something that alters your IP address but for my needs it was enough. To detect the IP address I am using the following ipapi.co API, specifically the following /GET ipapi.co/json/ endpoint which results with a simple JSON that you can retrieve the user's country code from.