Topic: Created Marker Not Auto Moving

I have a small mini map in my app and created a marker on it:

userMarker = OnlineMapsMarkerManager.CreateItem(new Vector2(0, 0), null, "Your Location");

My problem is, the marker doesn't change position on the map. I have location services on and it does initially find my location.

I subscribed to OnLocationChanged:

locationService.OnLocationChanged += OnLocationChanged;

private void OnLocationChanged(Vector2 position)
{
       
    // Change the position of the marker.
    userMarker.position = position;
       
    // Redraw map.
    OnlineMaps.instance.Redraw();
   
}


Under Location Services on the Map GO I have set:

* Update Map Position [Checked]
* Auto Stop on Input [UnChecked]
* Restore After [5 sec]
* Create Marker [UnChecked]

Any ideas?

Re: Created Marker Not Auto Moving

Hello.

There can be a lot of problems here, for example your marker is on the first map and OnlineMaps.instance is referring to the second map, the method is not called for some reason, or the same position is passed.

You need to make sure that your method is called and that all objects are referenced correctly.

Kind Regards,
Infinity Code Team.

uContext is Editor PowerPack (more than 40 tools) that take your workflow in Unity Editor to a next level, simplifies working with content, adds new features, corrects and improves the editor’s built-in behaviors. Click here to download uContext Basic for free.

Re: Created Marker Not Auto Moving

Alex Thanks for the reply. To be clear, the mini map is the only map in the scene. It overlays a UI Canvas and is looked at with a separate camera. I'm using the OnlineMaps instance in all script references.

Re: Created Marker Not Auto Moving

Your code looks correct, so unfortunately I don't know what exactly is wrong.
You need to debug this.
Or you can email me your project (support@infinity-code.com) and I'll debug it for you.
To make it clear:
I don't need your working project.
I need any temporary project where the problem is appears.

Kind Regards,
Infinity Code Team.

uContext is Editor PowerPack (more than 40 tools) that take your workflow in Unity Editor to a next level, simplifies working with content, adds new features, corrects and improves the editor’s built-in behaviors. Click here to download uContext Basic for free.

Re: Created Marker Not Auto Moving

I'm making a few changes based on your initial comments and changing to a UIRawImage map since I am putting it on top of a map.

I'll let you know either way and send you a copy if I can't work it out.

Thanks!

6 (edited by AppFreak 2021-04-15 23:50:59)

Re: Created Marker Not Auto Moving

Alex,

As per your suggestion, I created a specific set of Map variables and assigned the Map GO to them:

    [Header("Online Maps Vars")]
    public OnlineMaps onlineMaps;
    public OnlineMapsControlBase onlineMapsControlBase;
    public OnlineMapsCameraOrbit onlineMapsCameraOrbit;
    public OnlineMapsBuildings onlineMapsBuildings;
    public OnlineMapsProvider onlineMapsProvider;
    public OnlineMapsLocationService onlineMapsLocationService;
    public OnlineMapsMarkerManager onlineMapsMarkerManager;
    public OnlineMapsMarkerBase onlineMapsMarkerBase;


In my manage marker script, I declared the marker:

    private OnlineMapsMarker userMarker;

Then in the same script I create the marker in the Start method but it does not allow me to use the variable I created for the OnlineMapsMarkerManager so I'm not sure if that causes and issues and one of the reasons the marker is not auto moving:


    private void Start()
    {
       
        // Create a new marker.
        userMarker = OnlineMapsMarkerManager.CreateItem(new Vector2(0, 0), null, "Your Location");

        // Get instance of LocationService.
        //OnlineMapsLocationService locationService = OnlineMapsLocationService.instance;

        if (GlobalVariables.Instance.onlineMapsLocationService == null)
        {
            Debug.LogError(
                "Location Service not found.\nAdd Location Service Component (Component / Infinity Code / Online Maps / Plugins / Location Service).");
            return;
        }

        // Subscribe to the change location event.
        GlobalVariables.Instance.onlineMapsLocationService.OnLocationChanged += OnLocationChanged;
       
    }

   
   
    // Get Loc info when the location has changed
    private void OnLocationChanged(Vector2 position)
    {
       
        // Change the position of the marker.
        userMarker.position = position;

        // Redraw map.
        GlobalVariables.Instance.onlineMaps.Redraw();
   
    }


Does the OnLocationChanged always get called or do I need something in an Update method?

Re: Created Marker Not Auto Moving

Your code looks good and I don't see any obvious problem here.

OnLocationChanged is called when your GPS location or location in GPS emulation has changed.

Kind Regards,
Infinity Code Team.

uContext is Editor PowerPack (more than 40 tools) that take your workflow in Unity Editor to a next level, simplifies working with content, adds new features, corrects and improves the editor’s built-in behaviors. Click here to download uContext Basic for free.