2016-11-07 34 views
-2

我目前使用的是Jekyll 3.30,我正在尋找建立商店定位器。我正在計劃當前的功能。使用Jekyll建立商店定位器

  1. 轉到定位器頁面
  2. 類型在郵編/郵政編碼萬里
  3. 選擇號碼客場 - > 20英里/ 40英里/ 60英里
  4. 的店鋪一覽結果最接近第一。

現在我的問題是,如何在使用Google地理編碼服務時存儲要查詢的位置的最佳方式?

是否有可能將位置存儲在_data文件夾中作爲JSON?

或者是更好地存儲位置像內容一樣的地方,然後通過ajax檢索他們?

編輯:

所以我已經能夠從數據文件中提取數據到JSON並將其送入谷歌地圖和返回的距離。但是,如何將距離分配回原始項目?

//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); 

    } 
} 

回答

0

任何可以提供網絡資源(您的json文件)都可以。

然而,隨着傑奇服務,將在我看來優點2:

  1. 這將具有相同的網址爲您的網頁,因此,沒有跨域問題,當你加載
  2. 數據將與您的應用程序在同一代碼存儲庫中

爲避免手動編寫json,您可以將商店存儲在_post中,並使用液體模板生成json文件。

你的信息的元數據在YAML頭如:

--- 
guid: "3f8bf46a9c21" 
title: "Mont Lozère" 
latlng: "44.425962, 3.739340" 
youtubeId: "0OHCYmOMZmg" 
--- 

您的JSON範本看起來像(對不起我的例子是JSONP但你的想法):

--- 
--- 
{% assign posts = site.posts | where:"type", "youtube" %} 
/* Number of places: {{ posts | size }} */ 
processJSON([ 
    {% for post in posts %} 
    { 
     "guid": "{{ post.guid }}", 
     "title": "{{ post.title }}", 
     "latlng": "{{ post.latlng }}", 
     "youtubeId": "{{ post.youtubeId }}" 
    } 
    {% unless forloop.last %},{% endunless %} 
    {% endfor %} 
]); 

在此示例中,位置(您的商店)位於文件夾_post/youtube中,而_config.yml提供「類型」(用於將它們從其他帖子中選中)

defaults: 
    - scope: 
     path: "_posts/youtube" 
    values: 
     type: "youtube" 

您可以從https://github.com/franceimage/franceimage.github.io