Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Autocompleted Address breakdown into multiple fields

More
5 years 7 months ago #173264 by dirk01
Tpartner,

Thank you for the quick respons.

It works for me too!

It saved my day and a couple of days work.:)

It is a great way of questioning someone's displacements.

Dirk
The topic has been locked.
More
5 years 7 months ago #173265 by jelo

tpartner wrote: The attached sample survey works for me in group-by-group if I disable AJAX mode in the theme options.

Any idea why it works with AJAX on in the other displaymode? The different displaymodes alone are a nice source of bugs.

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 7 months ago #173267 by tpartner
I think that in "all-in-one" mode, the AJAX is not used as everything is loaded as a single page.

I did not bother to debug the problem when AJAX is used (I rarely use it).

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • davidg1982
  • davidg1982's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 7 months ago #188683 by davidg1982
How do I add Lat and Long to the script?

I am not sure how to do that.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 7 months ago - 4 years 7 months ago #188687 by tpartner
You can use the place.geometry.location.lat() and place.geometry.location.lng() functions:

Code:
<script>
  function init() {
    $('#displayCounty').hide();
 
    // Disable the partial-address inputs
    $('#question{QID} input:text:gt(0)').prop('readonly', true);
 
    // Un-comment below to hide the partial-address inputs
    //$('#question{QID} input:text:gt(0)').hide();
 
    var input = document.getElementById('answer{SID}X{GID}X{QID}SQ001');
    var autocomplete = new google.maps.places.Autocomplete(input);
 
    autocomplete.addListener('place_changed', function() {
      var place = autocomplete.getPlace();
      var components = place.address_components;
      if (components) {
        for (var i = 0, l = components.length; i < l; i++) {
          var component = components[i];
          if (component.types &amp;&amp; component.types.indexOf('street_number') !== -1) {
            $('#answer{SID}X{GID}X{QID}SQ002').val(component.long_name);
          }
          if (component.types &amp;&amp; component.types.indexOf('route') !== -1) {
            $('#answer{SID}X{GID}X{QID}SQ003').val(component.long_name);
          }
          if (component.types &amp;&amp; component.types.indexOf('locality') !== -1) {
            $('#answer{SID}X{GID}X{QID}SQ004').val(component.long_name);
          }
          if (component.types &amp;&amp; component.types.indexOf('administrative_area_level_2') !== -1) {
            $('#displayCounty').text('County: ' + component.long_name);
            $('#displayCounty').show();
            $('#answer{SID}X{GID}X{QID}SQ005').val(component.long_name);
          }
          if (component.types &amp;&amp; component.types.indexOf('administrative_area_level_1') !== -1) {
            $('#answer{SID}X{GID}X{QID}SQ006').val(component.long_name);
          }
          if (component.types &amp;&amp; component.types.indexOf('country') !== -1) {
            $('#answer{SID}X{GID}X{QID}SQ007').val(component.long_name);
          }
          if (component.types &amp;&amp; component.types.indexOf('postal_code') !== -1) {
            $('#answer{SID}X{GID}X{QID}SQ008').val(component.long_name);
          }
          $('#answer{SID}X{GID}X{QID}SQ009').val(place.geometry.location.lat(place.address_components.formatted_address));
          $('#answer{SID}X{GID}X{QID}SQ010').val(place.geometry.location.lng(place.address_components.formatted_address));
        }
      }
    });
  }
  google.maps.event.addDomListener(window, 'load', init);
</script>

Sample survey attached:

File Attachment:

File Name: limesurvey...7672.lss
File Size:23 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 4 years 7 months ago by tpartner.
The following user(s) said Thank You: davidg1982
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose