I’m currently developing server side to Application,
in the App I have a lot of interest point in big area (over 1000 points)
and I want to find the nearest points to user device.
I’ve try to used:
.GetDistanceTo(GeoCoordinate);
from the libary:
System.Device.Location;
example query:
from point in db.Points
where ((new GeoCoordinate(point.lat,point.lng)).GetDistanceTo(new GeoCoordinate(coordinates[0],coordinates[1]))<1000))
select point
but in the Linq Query it’s not supported and if I try to use it on a List<> or an Array it takes too long…
How can I do it better and faster?
Thanks
I assume that you are performing this computation often, otherwise iterating over a thousand points should not take a large amount of time – certainly under a second.
Consider caching the points in memory as GeoCoordinates, since I am guessing the bulk of the time may be spent allocating memory and instantiating the objects, rather than computing the distance. From the existing list of GeoCoordinates, you could then do a computation against an existing Geocoordinate that is already instantiated.
Ex:
On the application load, store all points into memory, possibly on a background thread.
Then, take your point you are trying to search and loop over points
Iif that still isn’t fast enough, consider caching the last searched point and returing a known list if the new search is within the same bounds.