<fieldset class="module aligned {{ fieldset.classes }}"> 
    
    {% if fieldset.name %}
        <h2>{{ fieldset.name }}</h2>
    {% endif %} 
    
    {% if fieldset.description %} 
        <div class="description">
            {{ fieldset.description|safe }}
        </div> 
    {% endif %} 
    
    {% for line in fieldset %} 
    
        <div class="form-row{% if line.fields|length_is:'1' and line.errors %} errors{% endif %}{% for field in line %}{% if field.field.name %} field-{{ field.field.name }}{% endif %}{% endfor %}"> 
            {% if line.fields|length_is:'1' %}
                {{ line.errors }}
            {% endif %} 
            {% for field in line %} 
                <div{% if not line.fields|length_is:'1' %} 
                    class="field-box{% if field.field.name %} field-{{ field.field.name }}{% endif %}{% if not field.is_readonly and field.errors %} errors{% endif %}"{% endif %}> 
                    {% if not line.fields|length_is:'1' and not field.is_readonly %}
                        {{ field.errors }}
                    {% endif %} 
                    {% if field.is_checkbox %} 
                        {{ field.field }}
                        {{ field.label_tag }}
                    {% else %}
                        {{ field.label_tag }} 
                        {% if field.is_readonly %} 
                            <p>{{ field.contents|linebreaksbr }}</p> 
                        {% else %} 
                            {{ field.field }}
                            {% ifequal field.field.name "address" %}
                                <button id="button-{{ forloop.parentloop.parentloop.parentloop.counter0 }}"
                                    onclick="showAddress('{{ forloop.parentloop.parentloop.parentloop.counter0 }}','id_marker_set-{{ forloop.parentloop.parentloop.parentloop.counter0 }}-address', 'id_marker_set-{{ forloop.parentloop.parentloop.parentloop.counter0 }}-lat', 'id_marker_set-{{ forloop.parentloop.parentloop.parentloop.counter0 }}-lng');
                                    return false;">
                                        Récupérer la lattitude et la longitude
                                </button>
                            {% endifequal %}
                        {% endif %} 
                    {% endif %} 
                    {% if field.field.help_text %} 
                        <p class="help">{{ field.field.help_text|safe }}</p> 
                    {% endif %} 
                </div> 
            {% endfor %} 
        </div> 
    {% endfor %} 
</fieldset>
<script type="text/javascript">
    function showAddress(id,address,lat,lng) {
        var GeocoderOptions = {
            'address' : document.getElementById(address).value,
            'region' : 'FR'
        }
        function GeocodingResult(results, status) {
            if( status == google.maps.GeocoderStatus.OK ) {
                document.getElementById(lat).value = results[0].geometry.location.jb;
                document.getElementById(lng).value = results[0].geometry.location.kb;
                    marker[id] = ({
                    'id':id,
                    'lat':results[0].geometry.location.jb,
                    'lng':results[0].geometry.location.kb,
                    'title':'titre',
                    'infoWindow': {
                        content: '<h1>titre</h1><p></p>'
                    }
                })
                map.addMarker(marker[id]);
            }
            else {
                alert("La géolocalisation de cette addresse n'est pas possible !");
            }
        }
        var geocoder = new google.maps.Geocoder;
        geocoder.geocode(GeocoderOptions, GeocodingResult);
    }
</script>
