Get updated values from gps as moving

So, this may sound a little stupid but I have a basic question.
I am using the script from the documentation to get the longtitude and latitude to an android device.
LocationService.Start


It works fine and I actually get very accurate results.
My problem is how can I make it change and get the new values while I am moving.
It says that by default it changes every 10 meters, but when I try and move and I still have my application running it doesn’t change. Do I have to put the function in Update() or somewhere else in order for it to be updated and change when I move?
Is there any other way?

You have off course continuously get the current position from the LocationService.

The whole thing works like this:

  • Check if LocationService is enabled by User (whether the user has GPS and Co turn on for the device)
  • Start the LocationService → LocationService.Start()
  • check the status of the LocationService → LocationService.status (LocationServiceStatus.Running is what you need)
  • then continuously ( like in Update() ) read out LocationService.lastData.latitude and LocationService.lastData.longitute.

Look at the script from zapantis88 which has most of it in there somehow, except the continuous readout of the values is missing.

@Troula did you find the solution?i have the exact same problem.

@Ramesh_New here is my code if you can help me i am trying a week to find a solution.I am using galaxy s6 android version 5.1.1 and unity 5.3.5p6
.when i open the app i get the coordinates but they never update.

using UnityEngine;
using UnityEngine.SceneManagement;
using System.Collections;
using UnityEngine.UI;

public class DetectLocation : MonoBehaviour
{

    private Vector2 targetCoordinates;
    private Vector2 deviceCoordinates;
    private float distanceFromTarget = 0.0002f;
    private float proximity = 0.001f;
    private float sLatitude, sLongitude;
    public float dLatitude = 38.235406f, dLongitude = 21.768376f;
    private bool enableByRequest = true;
    public int maxWait = 10;
    public bool ready = false;
    public Text text;

    void Start()
    {
        targetCoordinates = new Vector2(dLatitude, dLongitude);
        StartCoroutine(getLocation());

    }



    IEnumerator getLocation()
    {
        LocationService service = Input.location;
        if (!enableByRequest && !service.isEnabledByUser)
        {
            Debug.Log("Location Services not enabled by user");
            yield break;
        }
        service.Start(1f, 0.1f);
        while (service.status == LocationServiceStatus.Initializing && maxWait > 0)
        {
            yield return new WaitForSeconds(1);
            maxWait--;
        }
        if (maxWait < 1)
        {
            Debug.Log("Timed out");
            yield break;
        }
        if (service.status == LocationServiceStatus.Failed)
        {
            Debug.Log("Unable to determine device location");
            yield break;
        }
        else
        {
            text.text = "Target Location : " + dLatitude + ", " + dLongitude + "

My
Location: " + service.lastData.latitude + ", " + service.lastData.longitude;
sLatitude = service.lastData.latitude;
sLongitude = service.lastData.longitude;
}
//service.Stop();
ready = true;
startCalculate();

    }


    public void startCalculate()
    {
        deviceCoordinates = new Vector2(sLatitude, sLongitude);
        proximity = Vector2.Distance(targetCoordinates, deviceCoordinates);
        if (proximity <= distanceFromTarget)
        {
            text.text = text.text + "

Distance : " + proximity.ToString();
text.text += "
Target Detected";
SceneManager.LoadScene(“Temple”);
}
else
{
text.text = text.text + "
Distance : " + proximity.ToString();
text.text += "
Target not detected, too far!";
}
}
}

Ressurecting the thread in case someone can comment on it:

In our experience, reading the GPS location from Unity just returns the “last known” readings from the actual GPS sensor, which is usually out of date. This is on Android.

We see it very well since we use a map: after we start reading the location from Unity, the location can (and usually is) way off.

It seems that the GPS gets re-read only when the user starts Google Maps, the location precision doesn’t get better from Unity.

So, is there a way to force re-reading GPS?

I had the same issue on Android as @ivoras had (IOS works fine as far as I can tell on just the unity functions), I ended up writing a plugin that just calls the update function in native android code using the following tutorial:
http://markcastle.com/steps-to-create-a-native-android-plugin-for-unity-in-java-using-android-studio-part-1-of-2/

I was stuck on this issue for several days and don’t wish that fate on any of you. Follow the above tutorial and use the following code. Then just get the location in Input.location.lastData.

package YOURPACKAGENAMEHERE;

import android.annotation.SuppressLint;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Build;

import androidx.annotation.RequiresApi;

public final class LocationHelper {
    public static Context context;
    public static LocationManager locationManager;
    public static LocationListener locationListener;

    public static void setContext(Context context)
    {
        LocationHelper.context = context;

        locationManager = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE);
        locationListener = new LocationListener() {
        @Override
        public void onLocationChanged(Location location) {
        }};
    }

    @RequiresApi(api = Build.VERSION_CODES.P)
    @SuppressLint({"MissingPermission"})
    public static void StartUpdates()
    {
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 800, 0, locationListener);
    }

    public static void StopUpdates()
    {
        locationManager.removeUpdates(locationListener);
    }

    public static String test() { return "IT WORKS";}
}

Can’t believe this bug has existed for so long…