GPS Location in Unity 2020

Поделиться
HTML-код
  • Опубликовано: 25 ноя 2024

Комментарии • 59

  • @afterlife1578
    @afterlife1578 11 месяцев назад +6

    if you're not getting the values, make sure your phone location is on. A very simple thing but one which I didnt notice and spent 30 mins figuring out what's wrong.

  • @georgearida4144
    @georgearida4144 3 года назад +19

    Can you implement google map or ios map inside unity ? Can you do tutorial for that?

    • @bad_covfefe
      @bad_covfefe 2 года назад +2

      Did you ever figure out how to do this?

    • @tofaani
      @tofaani  2 года назад +6

      Ya sure we can do it. Will share when possible. Thanks

    • @tofaani
      @tofaani  Год назад +2

      Google Maps or iOS Maps inside Unity by using the Maps SDK for Unity, which is a set of tools and assets that can help you integrate location-based services into Unity games and applications. With this SDK, you can easily add real-world locations, geolocation-based experiences, and maps to your Unity projects, providing a rich and immersive experience for users. You can use the provided maps and geolocation data to implement custom location-based features in your projects, such as wayfinding, location-based games, and more. Additionally, you can use the Maps SDK for Unity to customize and style the map to fit the specific needs of your project.
      developers.google.com/maps/documentation/android-sdk/overview

    • @tofaani
      @tofaani  Год назад +2

      First, you need to download and import the Maps SDK for Unity into your Unity project.
      In your scene, add an empty game object and add the MapRenderer component to it.
      In the Inspector, set the Map Service property to either Google Maps or iOS Maps, depending on which map provider you want to use.
      To display a map, you will need to set the Latitude, Longitude, and Zoom properties of the MapRenderer component. You can use the device's GPS data to retrieve the user's current location, and use that to center the map.
      using UnityEngine;
      using UnityEngine.UI;
      using Mapbox.Unity.Map;
      using Mapbox.Utils;
      public class MapDisplay : MonoBehaviour
      {
      [SerializeField]
      AbstractMap map;
      void Start()
      {
      // Get the user's GPS location.
      float latitude = Input.location.lastData.latitude;
      float longitude = Input.location.lastData.longitude;
      // Set the map's center location to the user's GPS location.
      map.Initialize(new Vector2d(latitude, longitude), 10);
      }
      }

  • @hardworkerstudio
    @hardworkerstudio Год назад +3

    Could you please make a tutorial about speed of the device and distance?

    • @tofaani
      @tofaani  Год назад +1

      Ya sure and will share the script.

    • @hardworkerstudio
      @hardworkerstudio Год назад

      @@tofaani Thank you very much!!

    • @tofaani
      @tofaani  Год назад

      using UnityEngine;
      using UnityEngine.UI;
      public class GPSSpeed : MonoBehaviour
      {
      public Text speedText;
      private float speed = 0f;
      private float lastLatitude = 0f;
      private float lastLongitude = 0f;
      private float timeInterval = 0f;
      private void Start()
      {
      // Check if device supports location services
      if (!Input.location.isEnabledByUser)
      {
      Debug.LogError("Location services not enabled on device");
      return;
      }
      // Start location services
      Input.location.Start();
      // Set the desired accuracy for GPS data
      Input.location.Start(1f, 1f);
      // Store the current time to calculate the time interval later
      timeInterval = Time.time;
      }
      private void Update()
      {
      // Check if GPS data is available
      if (Input.location.status == LocationServiceStatus.Running)
      {
      // Calculate the time interval between the current frame and the previous frame
      float elapsedTime = Time.time - timeInterval;
      timeInterval = Time.time;
      // Calculate the distance between the current position and the previous position
      float distance = Vector2.Distance(new Vector2(lastLatitude, lastLongitude),
      new Vector2(Input.location.lastData.latitude, Input.location.lastData.longitude));
      // Calculate the speed using the distance and time interval
      speed = distance / elapsedTime;
      // Store the current latitude and longitude for the next frame
      lastLatitude = Input.location.lastData.latitude;
      lastLongitude = Input.location.lastData.longitude;
      }
      // Display the speed in the specified Text component
      speedText.text = "Speed: " + speed.ToString("F2") + "m/s";
      }
      private void OnDestroy()
      {
      // Stop location services when the script is destroyed
      Input.location.Stop();
      }
      }

  • @SohailKhan-dt1vj
    @SohailKhan-dt1vj 9 месяцев назад

    Hi we can we set the location system in which we press the Button of punch in share the current location to the app admin in the unity

  • @hardworkerstudio
    @hardworkerstudio Год назад +2

    Thank you very much! I subscrip you because of this tutorial!

  • @AntonioJose-pn6yp
    @AntonioJose-pn6yp 9 месяцев назад

    How could I obtain the speed of the device where the app is located?
    Thanks for the contribution, I couldn't find anything and it was perfect for me

  • @xiodcrlx
    @xiodcrlx Год назад +1

    perfect example, from very start to a complete solution! there is a bit more fiddly step to enable high accuracy location for Android build - but this is a good 'homework' =)

    • @ewanmacaulay7708
      @ewanmacaulay7708 9 месяцев назад

      Did you manage to get this working for Android build

  • @ronitnag8889
    @ronitnag8889 2 года назад +3

    the location usage description is not present in my player settings can u help me with this...

  • @gsdg-studio-dreibach7153
    @gsdg-studio-dreibach7153 Год назад +1

    Hi. No one tutorial... How convert this data to city, country, street etc.
    C# GetPlacemarksAsync don't work in unity...
    Do you know how to convert longitude/latitude to placemark data? Make a tutorial PLS.

    • @tofaani
      @tofaani  Год назад

      For your project it will be more work to do to create that solution. Or you can try a plug-in from Unity asset store name as AR + GPS Location or search for MapBox

  • @vladios_vladios
    @vladios_vladios Год назад +1

  • @tantan-fe9kp
    @tantan-fe9kp Год назад +1

    Hi, I don't know if you;ll read this but - what is the accuracy of the values? How far should I move for the values to change?

    • @tofaani
      @tofaani  Год назад +1

      Hi, There can be drag of 30 meters in some cases.

  • @nathalietomas8964
    @nathalietomas8964 3 года назад +3

    Hi ! Thank you for your video. Do you know if it is working when you haven't any connexion 4G ou GPS ?

    • @tofaani
      @tofaani  3 года назад +1

      GPS technology itself doesn't use data from the Internet, obtaining information (longitude and latitude) directly from satellites.
      This particular tutorial can work without a internet connection.

  • @lifeisgameplayit
    @lifeisgameplayit 2 года назад +1

    cool tutorial

  • @hardworkerstudio
    @hardworkerstudio Год назад

    and we can use GPS in Unity, But we still can't make it can works in background of mobiles, a GPS still useless?

    • @tofaani
      @tofaani  Год назад +2

      Yes, that's correct. Unity can access GPS data on mobile devices through the Input.location API. However, it will only work when the application is in the foreground and actively running. To continue using GPS data in the background, a plugin or native code would need to be used.

  • @QuoteoftheDay-q7r
    @QuoteoftheDay-q7r 2 года назад +1

    is it always changing when we walk to other place, or we need to quit first and then go back in?

    • @tofaani
      @tofaani  Год назад

      The GPS location in Unity is updated in real-time, and it changes as you move to different locations. You do not need to quit the application and go back in to see the updated location. The GPS location data is obtained from the device's GPS system, and it is constantly updated as you move.

    • @QuoteoftheDay-q7r
      @QuoteoftheDay-q7r Год назад

      @@tofaani hmmm so why I my coordinate not changing automatically

  • @mennaelnemr573
    @mennaelnemr573 3 года назад +1

    do you know ho to put game object at specific longitude and latitude ?

    • @tofaani
      @tofaani  3 года назад

      Answer to your question need bit more explanation as there no straight forward way of doing this. I will be create a tutorial on that soon. I have used it in my "AR Live App" where you can see different markers(info popups) at popular location near your current location using mobile camera.

  • @prahelikadutta
    @prahelikadutta Год назад

    Does it work in the Unity Editor?

    • @tofaani
      @tofaani  Год назад +1

      No , because it need to get gps data from phone

  • @kalhararajapaksha4382
    @kalhararajapaksha4382 3 года назад +7

    can you give me this source code?

    • @tofaani
      @tofaani  2 года назад +1

      You can get all tutorials source code here.
      github.com/tanveersabir/UnityEssentials

  • @zakiesz
    @zakiesz Год назад

    i cant find location usage descriptin when build for Android device

    • @tofaani
      @tofaani  8 месяцев назад

      Please, Do check permissions for locations for the app on your device.

  • @Adalplay1
    @Adalplay1 9 месяцев назад

    This example works on android?

    • @tofaani
      @tofaani  9 месяцев назад

      Hi, Yes it should work.

    • @tofaani
      @tofaani  9 месяцев назад +1

      And also make sure phone location on just incase not on by default

    • @Adalplay1
      @Adalplay1 9 месяцев назад

      @@tofaani thanks, it works now

  • @nikolaynikolaev7339
    @nikolaynikolaev7339 4 года назад +2

    How to get speed?

    • @tofaani
      @tofaani  4 года назад

      That's interesting. Soon, I will be uploading a video on speed.

    • @LawnMeower
      @LawnMeower 3 года назад +1

      dark web //s

  • @unitynocode
    @unitynocode Год назад

    Please share the code .cs file ! :( I have never coded C# before

    • @unitynocode
      @unitynocode Год назад

      Added a fix to ask GPS permission here : if (!Input.location.isEnabledByUser)

    • @mrorange21
      @mrorange21 Год назад

      code is in description

    • @tofaani
      @tofaani  Год назад +1

      Sure I will drop

  • @ISPAMA32
    @ISPAMA32 3 года назад +2

    Thank u

  • @kalhararajapaksha4382
    @kalhararajapaksha4382 3 года назад +2

    thank youu

    • @tofaani
      @tofaani  2 года назад

      You're welcome!

  • @МихаилПетров-я9л

    А как на андроид собрать?

    • @tofaani
      @tofaani  Год назад

      You mean create build on android. If yes , simply connect your android device and switch project to android and open build setting and create build

  • @alissonagroo5061
    @alissonagroo5061 3 года назад +3

    email contact

    • @tofaani
      @tofaani  2 года назад

      contact@code3interactive.com