How to use jquery-addresspicker jquery with rails 3.1

微笑、不失礼 提交于 2019-12-11 09:07:47

问题


I am trying to use jquery-addresspicker with rails 3.1 but I am not able to make it run.

Here is the link https://github.com/sgruhier/jquery-addresspicker and the documentation does not mention much.

Can anyone suggest how should I use it in my rails app?


回答1:


did you include google maps

<script src="http://maps.google.com/maps/api/js?sensor=false"></script>

and jquery-ui ?




回答2:


place the script code in the html, or in separate js file

<script>
        $(function() {
            var addresspicker = $( "#addresspicker" ).addresspicker();
            var addresspickerMap = $( "#addresspicker_map" ).addresspicker({
                regionBias: "fr",
              elements: {
                map:      "#map",
                lat:      "#lat",
                lng:      "#lng",
                locality: '#locality',
                country:  '#country'
              }
            });
            var gmarker = addresspickerMap.addresspicker( "marker");
            gmarker.setVisible(true);
            addresspickerMap.addresspicker( "updatePosition");

        });
    </script>


<div>
    <div class='input'>
      <%= f.label :address %><br />
      <%= f.text_field :address, :id => "addresspicker_map" %>
      <%= f.label :locality %><br />
      <%= f.text_field :locality, :id => "locality", :disabled => "true" %>
      <%= f.label :country %><br />
      <%= f.text_field :country, :id => "country", :disabled => "true" %>
      ...
    </div>
    <div id="map"></div>
    <div id="legend">You can drag and drop the marker to the correct location</div>
  </div>

this is a piece of tutorial I made. I haven't tried it, but this is a start for you. you'll have to style it with css from here:

https://github.com/sgruhier/jquery-addresspicker/blob/master/demos/demo.css

include the js file in the app from here:

https://github.com/sgruhier/jquery-addresspicker/tree/master/src

and images:

https://github.com/sgruhier/jquery-addresspicker/tree/master/demos/images




回答3:


This has been ported to rails here at this repo https://github.com/ddidier/address_picker-rails



来源:https://stackoverflow.com/questions/10393793/how-to-use-jquery-addresspicker-jquery-with-rails-3-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!