Topic: Find Markers within Range

I want the most efficient way of returning a list of markers within a given range of a specified point. I know I could just go through the entire collection of markers and compute the distance, but thought there might be something more along the lines of the code below:

            Collider[] hitColliders = Physics.OverlapSphere(position, range);
            HashSet<int> nearbyObjectIds = new HashSet<int>();
            List<WorldObject> nearbyObjects = new List<WorldObject>();
            for (int i = 0; i < hitColliders.Length; i++)

Will iterating through all the markers currently on the map be the best way to go about it, or is there some more elegant solution?

Thanks!

Re: Find Markers within Range

Hello.

This is one of the possible solutions.

But there is another way:
1. Сonvert Unity World Position into coordinates.
2. Calculate the distance to each marker (OnlineMapsUtils.DistanceBetweenPoints). If the distance is less than some value, this marker in the range.


This way will work much faster than Physics.OverlapSphere.

Kind Regards,
Infinity Code Team.

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

Re: Find Markers within Range

Thanks! Does that remain true if there are a large number of markers on the map?

Also, in looking into the efficiency of calculating distance issue, I found this article and wondered how it compared with what you have in the DistanceBetweenPoints code.

http://docs.unity3d.com/Manual/Directio … other.html

Re: Find Markers within Range

Hello.

It is also a good way. Much better than Physics.OverlapSphere.
I think this is the fastest way (your link).

Kind Regards,
Infinity Code Team.

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

Re: Find Markers within Range

Awesome, thanks!