-
Notifications
You must be signed in to change notification settings - Fork 0
English version
-
Recently, I received a task:
Change the logo/background for the loading screen if the user is in the Japanese market 🇯🇵
. -
When I got the task, I was confident it would be simple—just use
RegionInfo.CurrentRegion.TwoLetterISORegionName
to get the current region of the user's device. However, when running the game and logging the result, it didn’t work as expected. Even though I was in Vietnam, the results were inconsistent. I tested on various environments like Editor (Windows/macOS), iOS, and Android, but the results often returnedUS
orIV
, even though my device settings were set to Vietnam. -
After researching, I found several others facing the same issue:
-
I still haven’t found an explanation for why the results are incorrect.
- During my research, I found several ways to determine the user's region:
Example:
private void Start()
{
if (Application.systemLanguage == SystemLanguage.Japanese)
{
// Handle logic
}
}
✅ Advantages:
- Easy to use as it is built into Unity.
- No access permissions required.
❌ Disadvantages:
- Low accuracy because users can change their system language.
Example:
private void Start()
{
if (RegionInfo.CurrentRegion.TwoLetterISORegionName.Equals("JP"))
{
// Handle logic
}
}
Example: Using system region unity
private void Start()
{
if (RegionHelper.GetCurrentRegion().TwoLetterISORegionName.Equals("JP"))
{
// Handle logic
}
}
✅ Advantages:
- Easy to use as it is built into Unity.
- No access permissions required.
❌ Disadvantages:
- Medium accuracy because users can change their device region (though this is rare).
- Results may be incorrect in some cases (as mentioned above). However, I wrote a library to handle this issue and provide accurate results on Android/iOS.
- You can use the system region unity library to get the current region of the device.
-
Using some APIs, you can determine the user's location based on their IP address. Popular APIs include:
-
Example using ipinfo.io:
void Start()
{
StartCoroutine(GetIPRegion());
}
IEnumerator GetIPRegion()
{
UnityWebRequest www = UnityWebRequest.Get("https://ipinfo.io/json");
yield return www.SendWebRequest();
if (www.result == UnityWebRequest.Result.Success)
{
Debug.Log(www.downloadHandler.text);
}
else
{
Debug.LogError("Error: " + www.error);
}
}
Result when running the game:

✅ Advantages:
- No permissions required (easily accessible via third-party APIs).
- Can determine country, region, and city (usually accurate to the city level).
❌ Disadvantages:
- Requires an internet connection (must be online to access the API).
- Relies on third-party services (if the API is down or changes, results may be affected).
- Requires JSON parsing to extract necessary information.
- Results may be inaccurate if the user uses a VPN.
✅ Advantages:
- High accuracy (can determine latitude, longitude, and altitude).
- Useful for location-based games/apps (e.g., AR games, tracking).
❌ Disadvantages:
- Requires location access permissions (on Android/iOS, user consent is needed).
- Consumes battery and resources (especially for continuous tracking).
- Not available in environments with poor signal (indoors, basements).
(If anyone has used this method, feel free to contribute an example. Thanks in advance! 😊)
💡Method | ✅ Advantages | ❌ Disadvantages |
---|---|---|
System Language | - Easy to use with Application.systemLanguage - No permissions required |
- Low accuracy as users can change their language settings |
Device Region | - Easy to use with RegionInfo - No permissions required - Can be improved with libraries |
- Medium accuracy - May return incorrect values on some devices or operating systems |
Network IP (via API) | - Can accurately determine country, region, and city - No permissions required |
- Requires internet connection - Relies on third-party APIs - Inaccurate with VPN - Requires JSON parsing |
GPS | - High accuracy - Useful for location-based applications |
- Requires location permissions - Consumes battery - Ineffective in poor signal areas |
🔗 Reference library for more accurate device region detection: system-region-unity
-
Each method has its own advantages and disadvantages. Depending on the specific requirements of your application, you can choose the most suitable method.
-
In my case, I chose Method 2 because:
- It is easy to use, does not rely on third-party services, and does not require permissions.
- Medium accuracy is sufficient for my needs since my game allows offline play.
- Users rarely change their device region (or leave it on automatic settings).