Lime Survey - 地理定位响应(城市、国家/地区)参数 returns 最后 url
Lime Survey - geolocation response (city, country) params returns in end url
LimeSurvey - 单击调查 url,要求用户允许或阻止位置
即。地理定位脚本 运行 & return 当前城市和国家最后 url。
有没有可能。下面是我的脚本,如何在石灰调查中实现这一点。
任何建议,请
<script type="text/javascript">
var geocoder;
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(successFunction, errorFunction);
}
function initMap(){
}
//Get the latitude and the longitude;
function successFunction(position) {
var lat = position.coords.latitude;
var lng = position.coords.longitude;
codeLatLng(lat, lng)
}
function errorFunction(){
alert("Geocoder failed");
}
function codeLatLng(lat, lng) {
alert("Latitude: "+lat);
alert("Longtude: "+lng);
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(lat, lng);
geocoder.geocode({'latLng': latlng}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
//console.log(results)
if (results[1]) {
//formatted address
alert(results[0].formatted_address)
//find country name
for (var i=0; i<results[0].address_components.length; i++) {
for (var b=0;b<results[0].address_components[i].types.length;b++) {
//there are different types that might hold a city admin_area_lvl_1 usually does in come cases looking for sublocality type will be more appropriate
if (results[0].address_components[i].types[b] == "administrative_area_level_1") {
//this is the object you are looking for
city= results[0].address_components[i];
break;
}
if(results[0].address_components[i].types[b] == 'country'){
country = results[0].address_components[i];
break;
}
}
}
//city data
alert(city.short_name + " " + city.long_name)
//country data
alert(country.short_name + " " + country.long_name)
} else {
alert("No results found");
}
} else {
alert("Geocoder failed due to: " + status);
}
});
} </script>
<script async defer src="https://maps.googleapis.com/maps/api/js?key=YOUR_KEY&callback=initMap"
type="text/javascript"></script>
有什么帮助吗?提前致谢。
如果您的代码有效(否则:首先检查您的代码)。我只为 LimeSurvey 部分发言。
- 创建多文本问题类型:
- 代码地理位置
- 添加2个子问题代码CITY和CONTRY
- 添加class(使用高级设置)
hidden
则问题不显示。
- 停用 HTML 编辑器并将脚本放入 jquery ready (alternate solution use addScriptToQuestion 插件)
- 在您的 js 代码中的每个
{
之后添加一个 space 或一个换行符(在每个 }
之前添加一个 space )
- 将您上次提醒(您有 city.data 和 coutry.data)替换为
$("#answer{SGQ}CITY").val(city.short_name + " " + city.long_name);
城市
$("#answer{SGQ}COUNTRY").val(country.short_name + " " + country.long_name);
国家
- 您可以在调查中使用{GEO_CITY}和{GEO_COUNTRY}(在本页之后)
- 然后你就可以在你的url
http://example.org/?city={GEO_CITY}&country={GEO_COUNTRY}
中使用它了
使用 LimeSurvey 2.50 及更高版本(否则需要一些 javascript 来隐藏问题)
当 Denis 建议将这个缩写版本放在隐藏的 multiple-short-text 问题的源代码中时,它对我有用:`
var geocoder;
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(successFunction, errorFunction);
}
//Get the latitude and the longitude;
function successFunction(position) {
var lat = position.coords.latitude;
var lng = position.coords.longitude;
codeLatLng(lat, lng)
}
function errorFunction(){
console.log("Geocoder failed");
}
function codeLatLng(lat, lng) {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(lat, lng);
geocoder.geocode({
'latLng': latlng },
function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
for (var i=0; i<results[0].address_components.length; i++) {
for (var b=0;b<results[0].address_components[i].types.length;b++) {
// Find city name
// There are different types that might hold a city
// "locality" works for most of North America
// See here for types - https://developers.google.com/maps/documentation/geocoding/intro
if (results[0].address_components[i].types[b] == "locality") {
//this is the object you are looking for
city= results[0].address_components[i];
break;
}
// Find country name
if(results[0].address_components[i].types[b] == 'country'){
country = results[0].address_components[i];
break;
}
}
}
// City data
//console.log(city.short_name + " " + city.long_name);
$("#answer{SGQ}CITY").val(city.long_name);
// Country data
//console.log(country.short_name + " " + country.long_name);
$("#answer{SGQ}COUNTRY").val(country.long_name);
}
else {
console.log("No results found");
}
} else {
console.log("Geocoder failed due to: " + status);
}
});
}
`
LimeSurvey - 单击调查 url,要求用户允许或阻止位置
即。地理定位脚本 运行 & return 当前城市和国家最后 url。
有没有可能。下面是我的脚本,如何在石灰调查中实现这一点。
任何建议,请
<script type="text/javascript">
var geocoder;
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(successFunction, errorFunction);
}
function initMap(){
}
//Get the latitude and the longitude;
function successFunction(position) {
var lat = position.coords.latitude;
var lng = position.coords.longitude;
codeLatLng(lat, lng)
}
function errorFunction(){
alert("Geocoder failed");
}
function codeLatLng(lat, lng) {
alert("Latitude: "+lat);
alert("Longtude: "+lng);
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(lat, lng);
geocoder.geocode({'latLng': latlng}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
//console.log(results)
if (results[1]) {
//formatted address
alert(results[0].formatted_address)
//find country name
for (var i=0; i<results[0].address_components.length; i++) {
for (var b=0;b<results[0].address_components[i].types.length;b++) {
//there are different types that might hold a city admin_area_lvl_1 usually does in come cases looking for sublocality type will be more appropriate
if (results[0].address_components[i].types[b] == "administrative_area_level_1") {
//this is the object you are looking for
city= results[0].address_components[i];
break;
}
if(results[0].address_components[i].types[b] == 'country'){
country = results[0].address_components[i];
break;
}
}
}
//city data
alert(city.short_name + " " + city.long_name)
//country data
alert(country.short_name + " " + country.long_name)
} else {
alert("No results found");
}
} else {
alert("Geocoder failed due to: " + status);
}
});
} </script>
<script async defer src="https://maps.googleapis.com/maps/api/js?key=YOUR_KEY&callback=initMap"
type="text/javascript"></script>
有什么帮助吗?提前致谢。
如果您的代码有效(否则:首先检查您的代码)。我只为 LimeSurvey 部分发言。
- 创建多文本问题类型:
- 代码地理位置
- 添加2个子问题代码CITY和CONTRY
- 添加class(使用高级设置)
hidden
则问题不显示。 - 停用 HTML 编辑器并将脚本放入 jquery ready (alternate solution use addScriptToQuestion 插件)
- 在您的 js 代码中的每个
{
之后添加一个 space 或一个换行符(在每个}
之前添加一个 space ) - 将您上次提醒(您有 city.data 和 coutry.data)替换为
$("#answer{SGQ}CITY").val(city.short_name + " " + city.long_name);
城市$("#answer{SGQ}COUNTRY").val(country.short_name + " " + country.long_name);
国家
- 您可以在调查中使用{GEO_CITY}和{GEO_COUNTRY}(在本页之后)
- 然后你就可以在你的url
http://example.org/?city={GEO_CITY}&country={GEO_COUNTRY}
中使用它了
使用 LimeSurvey 2.50 及更高版本(否则需要一些 javascript 来隐藏问题)
当 Denis 建议将这个缩写版本放在隐藏的 multiple-short-text 问题的源代码中时,它对我有用:`
var geocoder;
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(successFunction, errorFunction);
}
//Get the latitude and the longitude;
function successFunction(position) {
var lat = position.coords.latitude;
var lng = position.coords.longitude;
codeLatLng(lat, lng)
}
function errorFunction(){
console.log("Geocoder failed");
}
function codeLatLng(lat, lng) {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(lat, lng);
geocoder.geocode({
'latLng': latlng },
function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
for (var i=0; i<results[0].address_components.length; i++) {
for (var b=0;b<results[0].address_components[i].types.length;b++) {
// Find city name
// There are different types that might hold a city
// "locality" works for most of North America
// See here for types - https://developers.google.com/maps/documentation/geocoding/intro
if (results[0].address_components[i].types[b] == "locality") {
//this is the object you are looking for
city= results[0].address_components[i];
break;
}
// Find country name
if(results[0].address_components[i].types[b] == 'country'){
country = results[0].address_components[i];
break;
}
}
}
// City data
//console.log(city.short_name + " " + city.long_name);
$("#answer{SGQ}CITY").val(city.long_name);
// Country data
//console.log(country.short_name + " " + country.long_name);
$("#answer{SGQ}COUNTRY").val(country.long_name);
}
else {
console.log("No results found");
}
} else {
console.log("Geocoder failed due to: " + status);
}
});
}
`