I am currently using Jekyll 3.30 and I am looking to build a store locator. I am planning on the current functionality.
- Goes to the Locator page
- Types in Zipcode / Postal code
- Selects Number of Miles Away -> 20 Miles / 40 Miles / 60 Miles
- List results of of stores that are closest first.
Now my question is how is the best way to store the locations to query against when using the google geocode service?
Is it possible to store the locations in the _data folder as JSON?
Or is it better to store the locations in a place like contenful and then retrieve them via ajax?
Edit:
So i have been able to pull data from the data file into json and feed it into the google maps and return the distance. But how do I assign the distance back to the original item?
//zipcode
var origin = '50539'
// list of locations
var destination = {{site.data.store | jsonify}}
//loop through and return the distance of each object
for (var i = 0; i < destination.length; i++ ){
var service = new google.maps.DistanceMatrixService();
service.getDistanceMatrix({origins: [origin],destinations: [destination[i].storeaddress],travelMode: 'DRIVING', unitSystem: google.maps.UnitSystem.IMPERIAL}, callback);
function callback (response,status) {
var distance = response.rows["0"].elements["0"].distance.text;
var store = destination;
console.log(distance + store[i].storename);
}
}