A project I am working on currently has the requirement for a postcode/location search within a selected radius of miles.
What is the best way of implementing such a search, I am currently using EZSearch for simple Examine based searches but I know this does not support such a search as it was created to allow simple Examine searches.
First you'll need to get all of your searchable locations into a list. Within your method that populates each of your location ViewModels, you'll want to extend to contain a GeoCoordinate object for each location (System.Device.Location.GeoCoordinate). Then this can be populated with pre-saved lat/long information about the address (I can cover this as well if needed).
With the lat/longs you can then hydrate the GeoCoordinate object like this:
location.GeoCoordinate = new System.Device.Location.GeoCoordinate(location.lat, location.long)
Now the clever part, take the search location entered by the user (or the start location), you can pass this address into Googles GeoCoding service to return a lat/long, which you can then inturn convert into a GeoCoordinate using the method above. So you should end up with one start GeoCoordinate, and a list of ViewModels with their own respective GeoCoordinates, you then find the nearest with this:
nearest = (from x in locations select x).OrderBy(x => x.GeoCoordinate.GetDistanceTo(start-location-geocoordinate)).ToList();
Just to add on regarding search radius, what I'm doing is looping back through my results and populating a DistanceToSearch parameter on each location. The GeoCoordinate.GetDistanceTo() returns the distance in meters. You can then use this to limit the results to a certain radius.
Postcode/location radius
Hello,
A project I am working on currently has the requirement for a postcode/location search within a selected radius of miles.
What is the best way of implementing such a search, I am currently using EZSearch for simple Examine based searches but I know this does not support such a search as it was created to allow simple Examine searches.
Many thanks,
Graham
I recently discovered .Net 4.6+ has built in methods for detecting distances between lat/longs co-ords.
I haven't got example code to hand but what you want to do is store all locations with their appropriate lat/longs.
When a user puts in their postcode or location, fire off a geocode request to Google Maps Geocoding api to return their lat/Long you can then use GeoCoordinate.GetDistanceTo to match the nearest results: https://msdn.microsoft.com/en-us/library/system.device.location.geocoordinate.getdistanceto(v=vs.110).aspx
Ok, I've found examples to show you what I mean, these all go on the assumption you're populating your Views with strongly typed models.
First you'll need to get all of your searchable locations into a list. Within your method that populates each of your location ViewModels, you'll want to extend to contain a GeoCoordinate object for each location (System.Device.Location.GeoCoordinate). Then this can be populated with pre-saved lat/long information about the address (I can cover this as well if needed).
With the lat/longs you can then hydrate the GeoCoordinate object like this:
Now the clever part, take the search location entered by the user (or the start location), you can pass this address into Googles GeoCoding service to return a lat/long, which you can then inturn convert into a GeoCoordinate using the method above. So you should end up with one start GeoCoordinate, and a list of ViewModels with their own respective GeoCoordinates, you then find the nearest with this:
Just to add on regarding search radius, what I'm doing is looping back through my results and populating a DistanceToSearch parameter on each location. The GeoCoordinate.GetDistanceTo() returns the distance in meters. You can then use this to limit the results to a certain radius.
is working on a reply...