- Posts: 1
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Identify the elements var mapQ = $('#question{QID}'); var mapInput = $('input.text.location', mapQ); var mapSGQA = mapInput.attr('id').replace(/answer/, '').replace(/_c/, ''); var map = gmaps[mapSGQA+'_c']; var marker = gmaps['marker__'+mapSGQA+'_c']; var addressQ = mapQ.prevAll('.text-short:eq(0)'); var addressInput = $('input.text', addressQ); // Add a "Search" button addressInput.after('<button class="geocode" type="button">Move Map</button>'); // Wait for the maps to load google.maps.event.addListenerOnce(map, 'idle', function(){ // Initialize geocoder var geocoder = new google.maps.Geocoder(); // Geocode look-up function function codeAddress() { var address = addressInput.val(); geocoder.geocode( { 'address': address}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { // Move the map and marker map.setCenter(results[0].geometry.location); marker.setPosition(results[0].geometry.location); // Record the new position mapInput.val(Math.round(results[0].geometry.location.lat()*10000)/10000 + " " + Math.round(results[0].geometry.location.lng()*10000)/10000); } else { alert("The search was not successful for the following reason: " + status); } }); } $('button.geocode').click(function(e) { codeAddress(); }); }); }); </script>
$('#answer{SGQ}').val(Math.round(results[0].geometry.location.lat()*10000)/10000 + ';' + Math.round(results[0].geometry.location.lng()*10000)/10000);
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Identify the elements var mapQ = $('#question{QID}'); var mapInput = $('input.text.location', mapQ); var mapSGQA = mapInput.attr('id').replace(/answer/, '').replace(/_c/, ''); var map = gmaps[mapSGQA+'_c']; var marker = gmaps['marker__'+mapSGQA+'_c']; var addressQ = mapQ.prevAll('.text-short:eq(0)'); var addressInput = $('input.text', addressQ); // Wait for the maps to load google.maps.event.addListenerOnce(map, 'idle', function(){ // Initialize geocoder var geocoder = new google.maps.Geocoder(); // Geocode look-up function function codeAddress() { var address = "{PERSDATA_PD002} Steyregg"; geocoder.geocode( { 'address': address}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { // Move the map and marker map.setCenter(results[0].geometry.location); marker.setPosition(results[0].geometry.location); map.panTo(marker.getPosition()) // Record the new position mapInput.val(Math.round(results[0].geometry.location.lat()*10000)/10000 + " " + Math.round(results[0].geometry.location.lng()*10000)/10000); $('#answer{SGQ}').val(Math.round(results[0].geometry.location.lat()*10000)/10000 + ';' + Math.round(results[0].geometry.location.lng()*10000)/10000); } else { alert("Automatische Adresssuche nicht erfolgreich. Fehler: " + status); } }); } codeAddress(); }); }); </script>