Search Unity

geolocation based ar app

Discussion in 'AR/VR (XR) Discussion' started by Stefan-3DBetrieb, Oct 9, 2017.

  1. Stefan-3DBetrieb

    Stefan-3DBetrieb

    Joined:
    Feb 28, 2017
    Posts:
    16
    Hi together,
    I would like to do a simple geolocated ar app.
    I would like to place some objects (buildings etc..) on a specific geo loaction in real world scale.
    If the user comes in the near of the object he can view the models placed in the real world.

    I thought that this is quiet simple with a toolkit like vuforia, but surpisingly I can`t find an example or tutorial for that.
    I am a beginner in unity and programming and have done some small unity projects at this time, for example an ar app with ARToolkit...

    Has anyone suggestions or an online tutorial how to get started?
    Wich toolkit should I prefer (ARToolkit, Vuforia, Wikitude, Kudan)?

    Thank you for your assistance,
    best regards, Stefan
     
  2. param_appm

    param_appm

    Joined:
    Jun 14, 2017
    Posts:
    34
    Hello Stefan,

    I think Vuforia should solve your purpose. You can use Vuforia for this project.
     
  3. Stefan-3DBetrieb

    Stefan-3DBetrieb

    Joined:
    Feb 28, 2017
    Posts:
    16
    Hi param,
    okay thank you for advice!
    Best regards, Stefan
     
  4. Karolina3D

    Karolina3D

    Joined:
    Nov 14, 2017
    Posts:
    1
    Hi Stefan :) I would like do very similar app how you and I have the same problems like You. Could you tell me how solved the problem and where you found help?
     
  5. ridhima1005

    ridhima1005

    Joined:
    Sep 25, 2018
    Posts:
    2


    Hello, I am working on a similar android app and I am using AR Core. Could you help me with how to place objects at fixed geolocation and the user can view them when he is near that object?
     
  6. Stefan-3DBetrieb

    Stefan-3DBetrieb

    Joined:
    Feb 28, 2017
    Posts:
    16
    Hi together,
    unfortunatly I didn`t find a solution yet.
    I tried to use vuforia and got the gps system working with the tutorial of Matthew:

    The model shows up when I reached the position, but it kept it position relative to the camera, so I was not able to explore it by walking around...
    Anyone with a better solution??
    Best regards,
    Stefan
     
  7. LokeshKosuri

    LokeshKosuri

    Joined:
    Sep 4, 2018
    Posts:
    3
    Hi All,

    I am also trying to achieve the same using geo coordinates placing a game object at particular lat n long.
    but we want to place the object at particular position not inside a radius, is there any other alternative that we can try with?

    I tried this using mapbox but due to GPS accuracy isn't great and the objects move or float a lot.
    n i tried Matthew's example also using vuforia but dint get the expected result.

    Any thoughts or tips?
     
  8. Stefan-3DBetrieb

    Stefan-3DBetrieb

    Joined:
    Feb 28, 2017
    Posts:
    16
    Hi LokeshKosuri,

    I thought about modifying Matthews example:
    The script in the comments of "Devender Gupta" in the tutorial I mentioned works and the desired object appears when you reach a real life position in the radius of the given geolocation. The problem is that it doesn`t update the objects position relative to the camera when moving around.
    So I thought about calculating a repositioning vector for the update function to move the object to the correct distance to the camera.
    But relating to your comment with the low GPS accuracy it seems to be wasted time to try this...

    So I didn`t thougt that this would be as complicated at the end...
    Best regards,
    Stefan
     
    Last edited: Nov 7, 2018
  9. LokeshKosuri

    LokeshKosuri

    Joined:
    Sep 4, 2018
    Posts:
    3
    Hi @Stefan-3DBetrieb ,

    Thank you so much for the quick turnaround.
    Can you please provide that script? which you are talking about so that I can try n check your idea.
     
  10. Stefan-3DBetrieb

    Stefan-3DBetrieb

    Joined:
    Feb 28, 2017
    Posts:
    16
    Hi LokeshKosuri,
    here is the script from "Devender Gupta" called location.cs:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5.  
    6. public class location : MonoBehaviour
    7. {
    8.  
    9.     public static location Instance { set; get; }
    10.     public float currentLongitude = 0f;
    11.     public float currentLatitude = 0f;
    12.     public float originalLatitude;
    13.     public float originalLongitude;
    14.     public float radius;
    15.     Vector3 unityc = new Vector3();
    16.     public GameObject Model;
    17.  
    18.  
    19.     public void Start()
    20.     {
    21.  
    22.         Instance = this;
    23.         DontDestroyOnLoad(gameObject);
    24.         Model.SetActive(false);
    25.         StartCoroutine(GetCoordinates());
    26.     }
    27.  
    28.     IEnumerator GetCoordinates()
    29.     {
    30.  
    31.         while (true)
    32.         {
    33.             if (!Input.location.isEnabledByUser)
    34.             {
    35.                 Debug.Log("Location is Not enabled by user ");
    36.                 yield break;
    37.             }
    38.  
    39.             Input.location.Start(1f, .1f);
    40.             int maxwait = 20;
    41.             while (Input.location.status == LocationServiceStatus.Initializing && maxwait > 0)
    42.             {
    43.                 yield return new WaitForSeconds(1);
    44.                 maxwait--;
    45.             }
    46.  
    47.             if (maxwait <= 0)
    48.             {
    49.                 Debug.Log("Timed Out");
    50.                 yield break;
    51.             }
    52.  
    53.             if (Input.location.status == LocationServiceStatus.Failed)
    54.             {
    55.                 Debug.Log("Unable to determine location");
    56.                 yield break;
    57.             }
    58.  
    59.             else {
    60.                 currentLatitude = Input.location.lastData.latitude;
    61.                 currentLongitude = Input.location.lastData.longitude;
    62.                 Vector2 pass = new Vector2(currentLatitude, currentLongitude);
    63.                 Vector3 unityc = PolarToCartesian(pass);
    64.                 Calc(originalLatitude, originalLongitude, currentLatitude, currentLongitude, radius);
    65.             }
    66.         }
    67.     }
    68.     Vector2 CartesianToPolar(Vector3 point)
    69.     {
    70.         Vector2 polar;
    71.         //calc longitude
    72.         polar.y = Mathf.Atan2(point.x, point.z);
    73.         //this is easier to write and read than sqrt(pow(x,2), pow(y,2))!
    74.         Vector2 xzLen = new Vector2(point.x, point.z);
    75.         //xzLen = xzLen.magnitude;
    76.         //atan2 does the magic
    77.         polar.x = Mathf.Atan2(-point.y, xzLen.x);
    78.         //convert to deg
    79.         polar *= Mathf.Rad2Deg;
    80.         print(polar.x + " " + polar.y);
    81.         return polar;
    82.     }
    83.  
    84.     Vector3 PolarToCartesian(Vector2 polar)
    85.     {
    86.         //an origin vector, representing lat,lon of 0,0.
    87.         Vector3 origin = new Vector3(9.99139f, 76.28349f, 1);
    88.         //build a quaternion using euler angles for lat,lon
    89.         Quaternion rotation = Quaternion.Euler(polar.x, polar.y, 0);
    90.         //transform our reference vector by the rotation. Easy-peasy!
    91.         Vector3 point = rotation * origin;
    92.         print(point.x + " " + point.y);
    93.         return point;
    94.     }
    95.  
    96.     public void Calc(float xc, float yc, float xp, float yp, float r)
    97.     {
    98.         float distance = 0f, x = 0f, y = 0f, r1, r2, r3, c;
    99.         float R = 6378.137f;
    100.         r1 = xc * Mathf.Deg2Rad;
    101.         r2 = xp * Mathf.Deg2Rad;
    102.         x = (xp - xc) * Mathf.Deg2Rad;
    103.         y = (yp - yc) * Mathf.Deg2Rad;
    104.         r3 = Mathf.Sin(x / 2) * Mathf.Sin(x / 2) + Mathf.Cos(r1) * Mathf.Cos(r2) * Mathf.Sin(y / 2) * Mathf.Sin(y / 2);
    105.         c = 2 * Mathf.Atan2(Mathf.Sqrt(r3), Mathf.Sqrt(1 - r3));
    106.         distance = R * c * 1000f;
    107.         Model.SetActive(true);
    108.  
    109.         if (distance <= r)
    110.         {
    111.             Debug.Log("In range");
    112.             Model.SetActive(true);
    113.             transform.position = new Vector3(unityc.x, unityc.y, 0);
    114.         }
    115.         else
    116.         {
    117.             Debug.Log("Not in range");
    118.             Model.SetActive(false);
    119.         }
    120.  
    121.     }
    122.     public void Update()
    123.     {
    124.         currentLatitude = Input.location.lastData.latitude;
    125.         currentLongitude = Input.location.lastData.longitude;
    126.         Model.transform.eulerAngles += new Vector3(0, 1f, 0);
    127.  
    128.     }
    129. }
    130.  
    Best regards, Stefan
     
  11. SpiderJones

    SpiderJones

    Joined:
    Mar 29, 2014
    Posts:
    127
    I've used Mapbox for geolocation AR. In Mapbox I set a location with key value pairs. Then when the user is within a desired distance, I prompt the user to find a flat surface, then I use planar AR to render the object. Also with Mapbox I can display a map that shows where the user is and where the objects/GPS points are.
     
  12. honeybeeseverywhere

    honeybeeseverywhere

    Joined:
    Nov 19, 2018
    Posts:
    1
    Hi I wanted to ask if the AR you created on mapbox was like an AR map where users can find their way from one point to another? Have you succeeded in creating such a platform?
     
  13. SpiderJones

    SpiderJones

    Joined:
    Mar 29, 2014
    Posts:
    127
    The map is not AR, it's a top down map.
     
  14. travelhawk

    travelhawk

    Joined:
    Jan 13, 2017
    Posts:
    7
    @SpiderJones That sounds like a really good approach. Do you use it with a smartphone or a tablet. I'm thinking to use a tablet instead...
     
  15. SpiderJones

    SpiderJones

    Joined:
    Mar 29, 2014
    Posts:
    127
    @travelhawk I used it for iPad and iPhone and Android. I used Unity ARFoundation for AR, and MapBox for location stuff.
     
    Blarp likes this.
  16. Blarp

    Blarp

    Joined:
    May 13, 2014
    Posts:
    166
    I use Placenote for point cloud Anchoring and Mapbox just for a geo view of where things are (generally, since gps has a 20m variance).

    As long as people separate AR Anchoring and GPS Locations in their head, they can get a clear idea of how to go about this.
     
  17. viku_99

    viku_99

    Joined:
    Dec 14, 2016
    Posts:
    4
    MapBox and ARfoundation is not working ! throw Unity error google AR core already exist !
     
  18. SpiderJones

    SpiderJones

    Joined:
    Mar 29, 2014
    Posts:
    127
    I believe you need to delete all of MapBox's AR examples and tools, they conflict with Unity's ARCore XR Plugin