Autocompleted Address breakdown into multiple fields

Plus d'informations
il y a 4 mois 5 jours #171234 par davidg1982
davidg1982 a créé le sujet : Autocompleted Address breakdown into multiple fields
Good day all.

I have an address field were it is going to be autocompleted by google maps API, but I'd like to know how I can take the address and have them feed indivdual fields. As in, have the street address go to the street address field in the DB and have the zip code go to the zip code field in the DB for each survey response.

The end goal is to make this easier to slice and dice the data later on without much modification on the backend. Basically trying to get the data organized the way we want as it goes in.

Can I do this? How is it done? I am trying to find an easy answer for my web dev person.

Thanks!

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 4 mois 5 jours #171243 par Joffm
Joffm a répondu au sujet : Autocompleted Address breakdown into multiple fields
Hi,

you can use some equations with functions "strpos" and "substr" to find the delimiters between the parts of the address and then get the part with "substr".

How does this string look like? How do you want to split exactly? Please, give an example.

Best regards
Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 4 mois 5 jours #171253 par tpartner
tpartner a répondu au sujet : Autocompleted Address breakdown into multiple fields
How are you implementing the address look-up? If using the reverse Geocoding API, the returned "formatted_address" string may not always be structured the same - from the documentation: "The "formatted_address" results are not just postal addresses, but any way to geographically name a location.". Due to this, it may not be safe to parse the string with Expression Manager. You might want to access the elements of the returned "address_components" array directly.

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 4 mois 4 jours #171269 par davidg1982
davidg1982 a répondu au sujet : Autocompleted Address breakdown into multiple fields
Right now I am implementing it through a JS script based on advice from Google , but I am trying to figure out how to have the autocomplete fill in multiple fields, like in the example, then fill contact details, like city, state, etc. The manual, from my perspective, is not clear as how to achieve that.
I would appreciate something in the right direction.

Here is the code of the question. It's basic. I've removed my API key for security reasons.
<p><script src="https://maps.googleapis.com/maps/api/js?key=[APIKEY]&libraries=places"></script><script src="jquery.geocomplete.js"></script>Please enter your address.</p>
 
<p>powered by Google</p>
 
<p id="displayCounty"> </p>
<script>
  function init() {
    $('#displayCounty').hide();
    var input = document.getElementById('answer161767X10X131');
    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 &&
              component.types.indexOf('administrative_area_level_2') !== -1) {
            $('#displayCounty').text('County: ' + component.long_name);
            $('#displayCounty').show();
          }
        }
      }
    });
  }
  google.maps.event.addDomListener(window, 'load', init);
</script>

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 4 mois 4 jours #171275 par tpartner
tpartner a répondu au sujet : Autocompleted Address breakdown into multiple fields
Can you attach a small sample survey.

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 4 mois 1 jour #171338 par davidg1982
davidg1982 a répondu au sujet : Autocompleted Address breakdown into multiple fields
This should be it.
Pièces jointes :

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 4 mois 1 jour #171376 par tpartner
tpartner a répondu au sujet : Autocompleted Address breakdown into multiple fields
I would add sub-questions for all of the address components and use a script like this (replace YourAPIKey with a valid key):

<script src="https://maps.googleapis.com/maps/api/js?key=YourAPIKey&libraries=places"></script><script src="jquery.geocomplete.js"></script>
<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 && component.types.indexOf('street_number') !== -1) {
						$('#answer{SID}X{GID}X{QID}SQ002').val(component.long_name);
					}
					if (component.types && component.types.indexOf('route') !== -1) {
						$('#answer{SID}X{GID}X{QID}SQ003').val(component.long_name);
					}
					if (component.types && component.types.indexOf('locality') !== -1) {
						$('#answer{SID}X{GID}X{QID}SQ004').val(component.long_name);
					}
					if (component.types && 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 && component.types.indexOf('administrative_area_level_1') !== -1) {
						$('#answer{SID}X{GID}X{QID}SQ006').val(component.long_name);
					}
					if (component.types && component.types.indexOf('country') !== -1) {
						$('#answer{SID}X{GID}X{QID}SQ007').val(component.long_name);
					}
					if (component.types && component.types.indexOf('postal_code') !== -1) {
						$('#answer{SID}X{GID}X{QID}SQ008').val(component.long_name);
					}
				}
			}
		});
	}
	google.maps.event.addDomListener(window, 'load', init);
</script>



Sample survey (you will need to insert a valid API key in the src of the first script):

Fichier attaché :

Nom du fichier : limesurvey...7671.lss
Taille du ficher :30 ko

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Pièces jointes :
Les utilisateur(s) suivant ont remercié: davidg1982

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 3 mois 4 semaines #171502 par davidg1982
davidg1982 a répondu au sujet : Autocompleted Address breakdown into multiple fields
This worked! Great! Thank you for your help.

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 3 mois 16 heures #172640 par davidg1982
davidg1982 a répondu au sujet : Autocompleted Address breakdown into multiple fields
Question, is there a way we can hide all the fields the grayed out fields and still get all the information?

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 3 mois 3 heures #172647 par tpartner
tpartner a répondu au sujet : Autocompleted Address breakdown into multiple fields
Yes, that is already pointed out in the code comments.

Remove the preceding slashes in this line:

//$('#question{QID} input:text:gt(0)').hide();

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 2 mois 2 semaines #173248 par dirk01
dirk01 a répondu au sujet : Autocompleted Address breakdown into multiple fields
Hi,


I used this solution a lot!! in a questionnaire about mobility I am programming.

It worked great until I ran the full questionnaire.

It seems the script only works in 'all at once'-mode and the questionnaire is programmed to run in group by group mode.

Is it possible to get it working in group by group or question by question mode?


Best regards

Dirk

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 2 mois 2 semaines #173260 par tpartner
tpartner a répondu au sujet : Autocompleted Address breakdown into multiple fields
The attached sample survey works for me in group-by-group if I disable AJAX mode in the theme options.


Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Pièces jointes :

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 2 mois 2 semaines #173264 par dirk01
dirk01 a répondu au sujet : Autocompleted Address breakdown into multiple fields
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

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 2 mois 2 semaines #173265 par jelo
jelo a répondu au sujet : Autocompleted Address breakdown into multiple fields

tpartner écrit: 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.

Are you a student conducting a survey? If yes, tell me why you use LimeSurvey?
www.limesurvey.org/forum/development/116...y-you-use-limesurvey

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 2 mois 2 semaines #173267 par tpartner
tpartner a répondu au sujet : Autocompleted Address breakdown into multiple fields
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.

Connexion ou Créer un compte pour participer à la conversation.

Commencez dès maintenant !

Créez simplement un compte et commencez à utiliser LimeSurvey dès aujourd'hui.

Inscrivez-vous maintenant

Inscrivez-vous à notre Newsletter!