Maksim Posted May 8, 2017 Posted May 8, 2017 Hey folks. Quick question. I am working on a database for vendors on our forum. How can I create something so that members would be able to sort vendors/records based on distance? Thanks!
clearvision Posted May 10, 2017 Posted May 10, 2017 I assume you mean find vendors closest to the current member. 1) You will need lat/long stored for each business address. 2) You will need to determine "precise" location of the member either by a fixed address field or geolocation. Locating using HTML geolocation with javascript is probably required as ip geolocation done on the server is not very accurate. There are free api's to get ip location. 3) You then need a block/page/plugin to present sorted results using a database query. If you google "mysql find distance" you will get several pages of ideas on a query that will return items by distance using lat/lon pairs. 4) Google has geolocation api's to help with getting lat/long pairs for physical addresses if you want to generate them automatically. I just messed with the #2 for weather data and ended up using just an opt in zipcode field converted to lat/lon with a Google api. My membership was not interested in any sort of tracking of current physical location.
Maksim Posted May 10, 2017 Author Posted May 10, 2017 24 minutes ago, clearvision said: I assume you mean find vendors closest to the current member. 1) You will need lat/long stored for each business address. 2) You will need to determine "precise" location of the member either by a fixed address field or geolocation. Locating using HTML geolocation with javascript is probably required as ip geolocation done on the server is not very accurate. There are free api's to get ip location. 3) You then need a block/page/plugin to present sorted results using a database query. If you google "mysql find distance" you will get several pages of ideas on a query that will return items by distance using lat/lon pairs. 4) Google has geolocation api's to help with getting lat/long pairs for physical addresses if you want to generate them automatically. I just messed with the #2 for weather data and ended up using just an opt in zipcode field converted to lat/lon with a Google api. My membership was not interested in any sort of tracking of current physical location. Precisely. Have a database of vendors in ip pages. Instead of sorting by one the default factors, would like there to be a sort or search of those records based on distance to an entered zip code. So basically trying to figure out a way to do this with pages, as the info is already there or for a plugin or someone to do it.
clearvision Posted May 10, 2017 Posted May 10, 2017 If the vendors are in a single city, distance by just zipcode is not usually very useful at least for nearby zips, but you will still need to convert those zips to lat/lon pairs to have any hope of sorting on distance. You really have to do these when the vendor is added (or go thru and process those that exist) so you can have a query run on the database. You can get the lat/lon of the zip or address with a Google API including for the zip entered to search on. You will not be able to afford the api wait times of converting every vendor zip to lat/lon on the fly. How to modify the standard search ajax is beyond my skill set and would certainly involve a plugin. Probably easier to just have a separate linked distance page or block (possibly even with a map showing the location of the vendors once again using google's map api). The code on the page would just run the lat/lon query on the vendor databasse and present the returned records in order.
Maksim Posted May 10, 2017 Author Posted May 10, 2017 22 minutes ago, clearvision said: If the vendors are in a single city, distance by just zipcode is not usually very useful at least for nearby zips, but you will still need to convert those zips to lat/lon pairs to have any hope of sorting on distance. You really have to do these when the vendor is added (or go thru and process those that exist) so you can have a query run on the database. You can get the lat/lon of the zip or address with a Google API including for the zip entered to search on. You will not be able to afford the api wait times of converting every vendor zip to lat/lon on the fly. How to modify the standard search ajax is beyond my skill set and would certainly involve a plugin. Probably easier to just have a separate linked distance page or block (possibly even with a map showing the location of the vendors once again using google's map api). The code on the page would just run the lat/lon query on the vendor databasse and present the returned records in order. Honestly, even a distance by zip code would be more than fine... ie, put in a zip code to start, and then distance to the vendor from that zipcode. There may only be 1 result in that city anyway, or more likely 0. So yes, even if it is a separate search and then brings up the database built for ip pages? Want to take on the project? hehe. Shoot me a pm, will share details.
Maksim Posted May 16, 2017 Author Posted May 16, 2017 I just wanted to publicly thanks @clearvisionfor helping me with his brilliant solution. Looking forward to get it deployed shortly after testing. I am sure there are others in similar position.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.