1 (edited by digitalrock 2019-05-02 17:22:10)

Topic: Accuracy help needed

Hi,

I have an iOS app which displays users position at the center (I assume) of a tileset prefab.  (BTW I recently upgraded from v2 to latest of v3)

I subscribe to location changed events, and when an event occurs I add a 3D marker at the position. Theoretically as the accuracy improves and location events occur, the last marker should be at the center of the tileset.  Again, this is assuming the users position is always at the center of the map.  However the last marker added is not in the exact center, and I wanted to log the distance between the location change event position and (0,0).  Here's my code:

private void HandleLocationChangedEvent(Vector2 position)
    {
        // Calculate the distance in km between locations.
        _distance = OnlineMapsUtils.DistanceBetweenPoints(position, Vector2.zero).magnitude;

        // Get instance of OnlineMapsControlBase3D (Texture or Tileset)
        OnlineMapsControlBase3D control = OnlineMapsControlBase3D.instance;

        if (control == null)
            return;

        //Create a marker to show the current GPS coordinates.
        var marker = OnlineMapsMarker3DManager.CreateItem(position, _userLocPrefab);

        Controller.HandleLocationChanged(position);
    }

Do you see anything wrong with this?  How would I calc the distance in meters?

EDIT:  FYI, the location service control has "update map position" checked.

Re: Accuracy help needed

Hello.

I just tested your code and it works correctly.

Perhaps the problem is that your map is not centered.
The center of the map can be not in the center of the screen.
And this creates a visual effect that the marker is created not in the center of the map.

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: Accuracy help needed

Thanks Alex, it dos work.  I'm curious about the distance calc.  How do I convert the number to meters? (I tried dividing the distance by 1000, but the result was 11 meters, for the marker I was testing, which I think was wrong.  I think it was more like 1 meter, which I calculate with the use of my minimap.)

Re: Accuracy help needed

DistanceBetweenPoints returns the distance in kilometers.
To get the meters you need to multiply the distance by 1000.

Please explain in detail why you think that the distance is not correct?

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: Accuracy help needed

Okay I'll have to ask a few questions before I can get this figured out in detail.  First, for my purposes, the tileset map is centered like this:

_mapModelView.Position = new Vector3(OnlineMapsTileSetControl.instance.sizeInScene.x / 2, 0, OnlineMapsTileSetControl.instance.sizeInScene.y / -2);

I added some log statements to the code from the OP.  Here's the updated code and results below:

private void HandleLocationChangedEvent(Vector2 position)
    {

        /*
        * DEBUG TESTING ONLY below this comment
        */

        // Calculate the distance in km between locations.
        float distanceBetween = OnlineMapsUtils.DistanceBetweenPoints(position, Vector2.zero).magnitude;

        Debug.Log("distanceBetween: " + distanceBetween);

        _distance = Mathf.RoundToInt(distanceBetween);  // format for display

        Debug.Log("RoundToInt: " + _distance);

        _distance *= 1000;  

        Debug.Log("Distance: " + _distance + " meters between " + position + " and " + Vector2.zero);

        // Get instance of OnlineMapsControlBase3D (Texture or Tileset)
        OnlineMapsControlBase3D control = OnlineMapsControlBase3D.instance;

        if (control == null)
            return;

        //Create a marker to show the current GPS coordinates.
        var marker = OnlineMapsMarker3DManager.CreateItem(position, _userLocPrefab);

        Controller.HandleLocationChanged(position);
    }

Unity Console:

distanceBetween: 11164.32
RoundToInt: 11164
Distance: 11164000 meters between (-109.3, 45.6) and (0.0, 0.0)

It comes out 11 million meters away, which can't be correct.  Is my problem that the map center isn't Vector2.zero?

Thanks for your help.

Re: Accuracy help needed

Your calculation of the position of the map does not use the position of the camera.

Screenshot of the distance from Yandex Maps is attached.
Do not pay attention to the differences in values, since the points on Yandex Maps are set approximately.

Post's attachments

Attachment icon img1.png 224.97 kb, 61 downloads since 2019-05-03 

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

7 (edited by digitalrock 2019-05-03 22:16:27)

Re: Accuracy help needed

First, thanks for helping. 

1.  My camera is at (0,0,0).  This is why my map is moved to world center (code above).

2.  I thought the center of the map is where the user is located.  What I mean is, when the lat/lon of the users device reports a change, doesn't the tileset map update with that lat/lon in the center? (I don't mean the screen center, but the center point/position of the map).

3.  If #2 is incorrect, then is there a way to get the point at the center, so I can calc the distance from center?

Re: Accuracy help needed

You calculate the distance from the zero coordinates.
The center of the map and the user's position can have any coordinates.
And these coordinates are not always the same.

To get the coordinates of the center of the map, use OnlineMaps.position or OnlineMaps.GetPosition, depending on whether you need Vector2 or doubles.

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.