Hi all here's my situation: http://www.tamrielma.ps/skyrim/
I've added a search based on this well know example: https://developers.google.com/fusiontables/docs/samples/autocomplete
But it's not enough :D and I want that the map zooms and centers on the basis of the search results (that's a single markers not a group of, so I imagine that's not a "bound related" solution).
Thanks in advance for any suggestion
Interesting map. :-) I see you are already using the Google.visualization library for your autocompplete set up. I think that the same library (which uses FT JSONP API I believe) could be used to get the location values via a a callback, similar to your getData() callback.
E.g.
function changeQuery(value) {
value = value.replace("'", "\\'");
layerMarkers.setQuery("SELECT Location FROM "+ fusione +" WHERE Name = '" + value + "'");
// ADDED, using same query as above
var queryText = encodeURIComponent( "SELECT Location FROM "+ fusione +" WHERE Name = '" + value + "'");
var query = new google.visualization.Query('http://www.google.com/fusiontables/gvizdata?tq=' + queryText);
query.send(getLocationData);
}
// location may need parsing into LatLng object
function getLocationData(response) {
numRows = response.getDataTable().getNumberOfRows();
if(numRows == 1){
var loc_str = response.getDataTable().getValue(0, 0));
var tmp = loc_str.split(" ");
var lat = parseFloat(tmp[0]);
var lng = parseFloat(tmp[1]);
var zoom_level = 10;
var location = new google.maps.LatLng(lat,lng);
map.setCenter(location);
map.setZoom(zoom_level);
}
}
Related
Have a simple typeform embedded into a post in Wordpress. Nothing fancy at all. Embed code pulled direct from Typeform.
However, people can submit multiple times. ie. One person could theoretically do it 100 times.
Typeform have advised a cookie will solve this, and restrict a user to a single submission - but really do not know where to begin there. Is there a simple, quick fix that could do such a thing? Any ideas completely welcome!
One of the solutions could be only showing the embedded typeform if the cookie does not exist.
not really sure how you would do this in Wordpress.
But the logic is:
const embedElement = document.querySelector('.target-dom-node')
const displayed = getCookie("displayed_typeform");
if (displayed){
embedElement.innerHTML="<h2>Typeform already displayed once.</h2>"
} else if(!displayed && displayed === "") {
setCookie("displayed_typeform", true, 365);
showEmbed();
}
setCookie and getCookie are two functions that deal with cookie management
function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires="+ d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
function getCookie(cname) {
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for(var i = 0; i <ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
You can find a complete project that demonstrates this feature here.
I'm trying to search notes by the attribute sourceURL but it seems API is stripping away the protocol and the result is no results. Here is the code
var notesTransport = new Thrift.Transport(
Eventnote.Auth.oauth.getParameter(Eventnote.Auth.note_store_url_param));
var notesProtocol = new Thrift.Protocol(notesTransport);
var noteStore = new NoteStoreClient(notesProtocol, notesProtocol);
if (!noteStore) {
Eventnote.Logger.error("[EVERDU] Connection failure during getting note store");
return;
}
var filter = new NoteFilter();
filter.words = "sourceURL:" + url + "*";
try {
var results = noteStore.findNotes(Eventnote.Auth.get_auth_token(), filter,
0, 100);
...
The reasults objects looks like this
{
"startIndex":0,
"totalNotes":0,
"notes":[
],
"stoppedWords":null,
"searchedWords":[
"//github.com/sameersbn/docker-gitlab*"
],
"updateCount":18461
}
Is there something I am missing?
Not sure if that counts as a bug on Evernote's end or not, butyou can add double quotes around your url to make it work.
filter.words = "sourceURL:\"" + url + "*\"";
I am trying to set up personalised content in CQ5 using segmentation. When I use the out of the box "Page Hits" option it doesn't work. Is there some extra configuration I have to do to use Page Hits?
I've set up two segments applied to two teaser pages. For the first one I've used
number of page hits is less than 4.
For the second I've used number of page hist is greater than 3.
Note, the teasers show up when I use Referral Keywords to test so I think the rest of the configuration is correct.
Can anyone give some advice about how to get the Page Hits segmentations to work?
Just in case anyone else has this same problem, I solved it by using a session store and set a cookie on the users browser to record how many times they had been to a particular page. Using that, I was able to configure my segments and personalise areas of the page based on number of visits the user had made to that page.
Code for the session store:
//Create the session store
if (!CQ_Analytics.MyStore) {
CQ_Analytics.MyStore = new CQ_Analytics.PersistedSessionStore();
CQ_Analytics.MyStore.STOREKEY = "MYSTORE";
CQ_Analytics.MyStore.STORENAME = "myclientstore";
CQ_Analytics.MyStore.data={};
CQ_Analytics.MyStore.findPageName = function(){
var locationName = location.pathname;
var n = location.pathname.indexOf("html");
if(n !== -1){
locationName = locationName.split('.')[0];
}
return locationName.split("/").slice(-1);
}
CQ_Analytics.MyStore.title = CQ_Analytics.MyStore.findPageName() + "-pageviews";
CQ_Analytics.MyStore.loadData = function(pageViewed) {
CQ_Analytics.MyStore.data = {"pageviewed":pageViewed};
}
CQ_Analytics.MyStore.getCookie = function(cname) {
console.log("getting the cookie");
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1);
if (c.indexOf(name) == 0){
console.log("return value for cookie is " + c.substring(name.length,c.length) );
return c.substring(name.length,c.length);
}
}
return "";
}
CQ_Analytics.MyStore.setCookie = function(cname, cvalue, exdays) {
console.log("setting the cookie");
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires="+d.toUTCString();
document.cookie = cname + "=" + cvalue + "; " + expires;
}
CQ_Analytics.MyStore.checkCookie = function() {
console.log("checking for cookie");
var pViewd = CQ_Analytics.MyStore.getCookie(CQ_Analytics.MyStore.title);
if (pViewd != "") {
console.log("cookie is found and Viewed is " + pViewd);
pViewd = parseInt(pViewd) + 1;
CQ_Analytics.MyStore.setCookie(CQ_Analytics.MyStore.title, pViewd, 365);
CQ_Analytics.MyStore.loadData(pViewd.toString());
} else {
if (pViewd === "" || pViewd === null) {
console.log("cookie not found");
CQ_Analytics.MyStore.setCookie(CQ_Analytics.MyStore.title, "1", 365);
CQ_Analytics.MyStore.loadData("1");
}
}
}
CQ_Analytics.MyStore.checkCookie();
}
//register the session store
if (CQ_Analytics.CCM){
CQ_Analytics.CCM.register(CQ_Analytics.MyStore)
}
The most useful documentation I found was this: https://docs.adobe.com/docs/en/cq/5-6-1/developing/client_context_detail.html#par_title_34
All my markers are placed in the array "markersArray[]". I want to parse through them and retrieve their current individual latitude and longitude so I can add them to a string I then pass to PHP. Here are all the ways I've tried with no luck (getting latitude only for testing purposes).
function test() {
alert("markersArray.length " + markersArray.length)
for( var i = 0, n = markersArray.length; i < n; ++i ) {
var markerLat = parseFloat(markersArray[i].getAttribute("lng"))
//var markerLat = map.markersArray[i].getPoint().lat();
//var markerLat = map.markersArray[i].getPoint().lat();
//var markerLat = map.markersArray[i].latLng.lat().toFixed(3);
//var markerLat = map.markersArray[i].position.lat();
alert("markerLat " + markerLat)
}
}
I have no problem getting other attributes of the markers, I don't understand why this should be so difficult. :(
Why guess? The documentation says google.maps.Marker.getPosition() (assuming your markersArray contains google.maps.Marker objects, you don't provide the code that initializes it).
I'm trying to change the radius category/type filter for a checkbox, so I changed the var type to an array.
ORIGINAL WORKING:
var type;
for (var i = 0; i < document.controls.type.length; i++){
if (document.controls.type[i].checked){
type = document.controls.type[i].value;
}
}
startBox.setBounds(map.getBounds());
var search = {
// keyword: 'comocomo', // not needed with the autocomplete / startBox
bounds: map.getBounds()
};
if (type != 'establishment'){
search.types = [ type ];
}
places.search(search, function(placesArr, status){
THE ONE WITH THE ARRAY NOT WORKING: edited:
var type=[];
for (var i = 0; i < document.controls.type.length; i++){
if (document.controls.type[i].checked){
type.push(document.controls.type[i].value)
}
}
startBox.setBounds(map.getBounds());
var search = {
bounds: map.getBounds()
};
var quotedAndCommaSeparated = "'" + type.join("','") + "'";
alert(quotedAndCommaSeparated); // 'establishment','restaurant','lodging'
search.types = [ quotedAndCommaSeparated ];
I made many tests, and I don't see what I'm doing wrong. the map doesn't even show.
What's this meant to be, doesn't look like valid Javascript to me:
var type[];
Should be
var type = [];
Fix the javascript errors in your code otherwise the map won't show up.
Update:
What you have in quotedAndCommaSeparated is a string like "'a','b','c'" that looks a bit like the contents of an array: ['a','b','c']. But it's not an array, it's just a single string. If you check the length of your search.type array, I'm guessing it equals 1.
What you can do is split your string on the comma to turn it into an array:
search.types = quotedAndCommaSeparated.split(",");