Location Service doesn't work on tablet build, does with Unity Remote

For some reason I cant get location services to work. However! it does work fine when using Unity Remote 5. I’m using a Samsung Galaxy Tab 2 (Andriod 7.0). I’ve tried messing with the various location methods settings, double checked location permissions still don’t get anything. It gets stuck on initializing and times out. Is it something with my build settings? Tested it on a galaxy phone (Andriod 7) and it works fine too.

I’m using the simple code from the unity docs.

using UnityEngine;
using System.Collections;

public class TestLocationService : MonoBehaviour
{
    IEnumerator Start()
    {
        // First, check if user has location service enabled
        if (!Input.location.isEnabledByUser)
            yield break;

        // Start service before querying location
        Input.location.Start();

        // Wait until service initializes
        int maxWait = 20;
        while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0)
        {
            yield return new WaitForSeconds(1);
            maxWait--;
        }

        // Service didn't initialize in 20 seconds
        if (maxWait < 1)
        {
            print("Timed out");
            yield break;
        }

        // Connection has failed
        if (Input.location.status == LocationServiceStatus.Failed)
        {
            print("Unable to determine device location");
            yield break;
        }
        else
        {
            // Access granted and location value could be retrieved
            print("Location: " + Input.location.lastData.latitude + " " + Input.location.lastData.longitude + " " + Input.location.lastData.altitude + " " + Input.location.lastData.horizontalAccuracy + " " + Input.location.lastData.timestamp);
        }

        // Stop service if there is no need to query location updates continuously
        Input.location.Stop();
    }
}

Hi Layip,

wow, it’s now 4.5 year after your post and today I ran in exactly the same problem. My setup:

  • Unity 2021.3.9f1
  • Samsung Galaxy Tab S2 with Android 7
  • Getting location stucks in initialization (even when waiting 60 seconds)
  • All other Android devices successfully end initialization after a couple of seconds

have you been able to fix this?

Best,
Stefan
Heiwa Games