Shopify Liquid:如何将Google地址网址呈现到Google地图中

时间:2018-05-15 07:11:38

标签: jquery google-maps google-maps-api-3 shopify liquid

我正在制作通用解决方案,当我点击第一个地址图标时必须显示绑定到它的地址映射。与第二个相同。我已将模式添加为address-id作为类型文本,并在每个地址块的Shopify Edit主题促销块(代码底部的模式)下传递URL。我将address-id传递给data HTML属性。然后单击.promo块,我获取数据属性并存储在变量中,并将该变量传递给Jquery .html(mapAddress)。我点击每个地址图标获取当前地址或URL。我想将其显示为Map。我尝试将<iframe>直接添加到address-id到输入框address-id,但这样做不正常。它显示了Iframe值。这里有什么可以让谷歌地图网址呈现为地图? 谢谢。

Shopify液体模板

 <div class="sixteen columns featured_links">
    <div class="section clearfix feature">
      {% for block in section.blocks %}
        <div {% if block.settings.address-id != blank %} data-address="{{block.settings.address-id}}" {% endif %} class="promo {% if section.settings.featured_promos_per_row == 2 %}eight columns {% cycle 'alpha', 'omega' %}{% elsif section.settings.featured_promos_per_row == 3 %}one-third column {% cycle 'alpha', '', 'omega' %}{% else %}four columns {% cycle 'alpha', '', '', 'omega' %}{% endif %} {% if section.settings.featured_links_style != blank %}{{ section.settings.featured_links_style }} {% cycle 'delay-025s', 'delay-05s', 'delay-075s', 'delay-1s' %}{% endif %} center">
          {% if block.settings.link != blank %}
            <a href="{{ block.settings.link }}">
          {% endif %}

          <div class="{% if section.settings.rounded_image != blank %}rounded{% endif %}">
            {% if block.settings.image != nil %}
              <img  src="{{ block.settings.image | img_url: '300x' }}"
                    alt="{{ block.settings.image.alt }}"
                    data-src="{{ block.settings.image | img_url: '2048x' }}"
                    class="lazyload"
                    {% comment %} data-sizes="auto" {% endcomment %}
                    data-srcset=" {{ block.settings.image | img_url: '2048x' }} 2048w,
                                  {{ block.settings.image | img_url: '1600x' }} 1600w,
                                  {{ block.settings.image | img_url: '1200x' }} 1200w,
                                  {{ block.settings.image | img_url: '1000x' }} 1000w,
                                  {{ block.settings.image | img_url: '800x' }} 800w,
                                  {{ block.settings.image | img_url: '600x' }} 600w,
                                  {{ block.settings.image | img_url: '400x' }} 400w"
                     />
            {% else %}
              {% capture i %}{% cycle "1", "2", "3", "4", "5", "6" %}{% endcapture %}
              {{ 'collection-' | append: i | placeholder_svg_tag: 'placeholder-svg placeholder-svg--promotions' }}
            {% endif %}
          </div>

          {% if block.settings.title != blank %}
            <h3>{{ block.settings.title | escape }}</h3>
            {% if section.settings.show_divider %}
              <div class="feature_divider"></div>
            {% endif %}
          {% endif %}
          {% if block.settings.link != blank %}
            </a>
          {% endif %}

          {% if block.settings.text != blank %}
            {{ block.settings.text }}
          {% endif %}
        </div>

        {% if section.settings.featured_promos_per_row == 2 %}
          {% cycle '', '<br class="clear " />' %}
        {% elsif section.settings.featured_promos_per_row == 3 %}
          {% cycle '', '', '<br class="clear" />' %}
        {% else %}
          {% cycle '', '', '', '<br class="clear" />' %}
        {% endif %}
      {% endfor %}
    </div>

    {% if section.settings.contact_address != blank %}
    <br class="clear" />
    <div class="embed-container maps">
        <iframe width="100%" height="400" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d945.7084267048235!2d73.8854388291583!3d18.536415399212462!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x0%3A0xdda3387f821de029!2sWink+%26+Nod!5e0!3m2!1sen!2sin!4v1525613363322"></iframe>
    </div>
    {% endif %}    
  </div> 
</div>

JQuery Code onClick加载谷歌地图

<script>
$('.promo').click(function(){
    var mapAddress=$(this).attr("data-address");
  $('.embed-container, .maps').html(mapAddress);
}); 
</script>

模式

{% schema %}
{
        {
          "type": "text",
          "id": "address-id",
          "label": "Address-ID"
        }
}
{% endschema %}

1 个答案:

答案 0 :(得分:0)

我只需要使用mapAddress和Vola将src变量传递给Iframe .html()。有效 !!!

$('.promo').click(function(){
    var mapAddress=$(this).attr("data-address");
    $(".embed-container, .maps").html('<iframe  width="100%" height="400" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="'+mapAddress+'"><\/iframe>');
});