Search code examples
angularlocalizationgeolocationinternationalization

show different phone number based on the country in angular 8


I am working on an angular app where on a page, I need to show different cust care number for different country,

For Example,

  1. If user is logged-in from UK i will show 1-800-456-7891
  2. If user is logged-in from USA i will show 1-800-555-4444
  3. If user is logged-in from Japan, I will show 1-800-666-7474.

I am not positive on using i18n module, of angular, as website is in english only.

I thought of using HTML5 GeoLocation api to get the logged-in user country but than if depends on user to share the location info OR not.

can someone suggest me the best way of achieving this?


Solution

  • You can use one of the free services like : GEOJS or IPSTACK

    Example :

    HTTP GET : https://get.geojs.io/v1/ip/country/41.249.34.194.json

    return : {"name":"Morocco","country":"MA","ip":"41.249.34.194","country_3":"MAR"}

    NOTICE: IPSTACK have a limited quota 10000 request