WPS does not update the device position while running

When running a simple WPS scene and trying to place multiple objects at different positions using the AR World Positioning Manager and it’s OriginLatitude / Longitude method, the latitude and longitude values will not be updated after the initial start of the app.

Example: I used the script below to spawn cubes with a random material. However when trying to place multiple cubes at different locations, only the very first lat and long values will be used. When I restart the app at a different location, it’s now that different location.

using System;
using System.Collections;
using System.Collections.Generic;
using Niantic.Experimental.Lightship.AR.WorldPositioning;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.UI;
using Random = UnityEngine.Random;

public class PlaceNewObjectInfront : MonoBehaviour
{
    [SerializeField] private GameObject _objectToSpawn;

    [SerializeField] private ARWorldPositioningObjectHelper _positioningObjectHelper;
    
    [SerializeField] private Camera mainCam;

    [SerializeField] private Button placeObject;

    [SerializeField] private ARWorldPositioningManager _positioningManager;

    [SerializeField] private List<Material> _materials;

    private List<GameObject> instantiatedObjects;

   
    
    void Start()
    {
        instantiatedObjects = new();
        placeObject.onClick.AddListener(PlaceDownObject);
        StartCoroutine(PrintPosition());
    }


    IEnumerator PrintPosition()
    {
        while (true)
        {
            Debug.Log("Position is => long :"  + _positioningManager.WorldTransform.OriginLongitude + 
                      " lat: " + _positioningManager.WorldTransform.OriginLatitude + 
                      " Alt : " + _positioningManager.WorldTransform.OriginAltitude);

            yield return new WaitForSeconds(.7f);
        }

    }
    
    
    void PlaceDownObject()
    {
        // Vector3 position = mainCam.transform.position;

        GameObject newObject = Instantiate(_objectToSpawn);
        newObject.GetComponent<MeshRenderer>().material = _materials[Random.Range(0, _materials.Count-1)];

        newObject.name = $"{newObject.name} {instantiatedObjects.Count}"; 
        instantiatedObjects.Add(newObject);
        
        var lat = _positioningManager.WorldTransform.OriginLatitude;
        var longitude =  _positioningManager.WorldTransform.OriginLongitude;
        var altitude =  0;
        
        _positioningObjectHelper.AddOrUpdateObject(newObject, lat, longitude , altitude , Quaternion.identity );
        Debug.Log("(NO DEBUG) Adding Object " + newObject + " at Latitude:" + lat + " Longitude:  " + longitude + " Altitude: " + altitude);
        
    }
}

Hello! The reason it isn’t currently working is because you are sending the origin’s latitude and longitude as the update location for your object. Are you trying to spawn a WPS Object when a user clicks on the screen? If so you’d have to derive the longitude and latitude from the click position and pass that in as the parameters for the AddOrUpdateObject Method.

But shouldn’t the origin be the current position of the user? So e.g. I place a cube at my position then walk down the street and click place again, shouldn’t the origin position have changed to my new location and place the cube there?

This topic was automatically closed 2 hours after the last reply. New replies are no longer allowed.

If you are looking to track the current position of the user, I can recommend accessing the **ARWorldPositioningCameraHelper **script. It tracks the current longitude and latitude of the camera which might be of better use to you. The origin is simply the origin of the world coordinate system.

1 Like