different array for more google map on same page - google-maps-api-3

I have a problem with google map, delivery from this example: `Click here
I would like to create two maps, with different makers, and different paths on the same page that just does not seem to be able to pass new values ​​to google map for a different canvas-map based on the values ​​passed to the function.
In the my example: Click here clarifies my problem.
<p class="openmap" data-id="map">click here for map<p>
<p class="openmap" data-id="map1">click here for map1<p>
....
In the real script, the variable 'posts', is more complex and generates coordinates from html tables (two or more).
Someone has an idea how to fix?

The problem starts here:
function Tour_startUp(stops) {
if (!window.tour) window.tour = {
//code
}
}
It's obvious that Tour_startUp will do nothing when you call it the 2nd time, because on further calls the condition if (!window.tour) will be false. The result: both maps will use the same stops-argument that has been supplied at the first call.
Rethink the design of your application, avoid global variables and use OOP.

Related

How to analyze weird Goal Flow results? Is it possible to view specific users' journeys?

To help analyzing a site's user flow, I wrote a test bed in JavaScript, creating a new fake tracker, sending a few fake pageviews in like 1-2 second intervals according to a pretty extensive, randomized graph of expected views. I then set up goals in GA, containing funnels through certain pages. Then I left it running for a few hours, accumulating a few hundreds fake users.
Raw goal conversion percentages look good, page content flows too, BUT... when I'm looking at Goal Flow, some of the connections in the funnels don't make sense. For example 80% of my fake users seem to go from step "about" directly to step "success", skipping "product" and "payment", while - according to my test setup - that can't ever happen. (Step names used are examples to match the code below.)
I'd like to see exactly what paths did these particular users take - did some pages just not register, or did they register out of order, or what? Is there any way I can view RAW user journeys in GA, page by page?
For those interested, the testing code is basically like this:
ga("create","UA-0000000-2", "auto", "testtracker", {
'cookieName':"_ga_test_"+Date.now(),
'cookieExpires':120,
'clientId': 'cid-'+Date.now(),
});
var spd=1500;
var delay=0;
function pageview(page) {
setTimeout(function() {
ga("testtracker.send","pageview",page);
console.log("Sending: "+page);
},delay+=spd);
}
pageview("start");
if (Math.random()<.60) pageview("about");
if (Math.random()<.30) {
pageview("product");
if (Math.random()<.20) {
pageview("payment");
if (Math.random()<.70) {
pageview("success");
}
}
}
Apparently, I still have a lot to learn about GA.
The solution is to use Audience -> User Explorer and defining a very specific Section based on the suspicious sequence of pages does show individual users matching that pattern. And indeed somehow GA logged a pretty large number of such odd users for me, perhaps failing to register pages visited in too narrow time intervals.
I'm leaving the question for posterity, and perhaps for those who can find my code snippet useful.

Errors When Calculating Distance Between Two Addresses

I have the following script which is being used in a spreadsheet to calculate the driving distance between two cities or a city and a zip code of another city. It is being run for approximately 25 locations simultaneously. To better explain, I have cell B3 in which I enter a new city every time. The script is then used in cells adjacent to my 25 plant locations to calculate the distance from each of my plants to the variable city.
It uses google sheets built in mapping api and works on 80% of the calculations but returns "TypeError: Can Not Read Property "legs" from undefined. (line 16). The plants that it fails on vary with every new city so its not like it is for certain locations. It is almost like the api times out before it completes some of them. I split it into two separate scripts with a varied name and that worked for a day but then 20% fail again.
To make things slightly more odd, I have another script that sorts the plants based on closest distance to the variable address. When you sort the plants, even the ones with errors go to their correct location based on distance. So it is like the distance script is obtaining the correct disance but displaying the error anyways.
Clear as mud? Would love any input I could get on how to correct the issue or an alternate mapping api that could solve my problems.
function distancecalcone(origin,destination) {
var directions = Maps.newDirectionFinder()
//Set the Method of Transporation. The available "modes" are WALKING, DRIVING, BICYCLING, TRANSIT.
.setMode(Maps.DirectionFinder.Mode.DRIVING)
//Set the Orgin
.setOrigin(origin)
//Set the Destination
.setDestination(destination)
//Retrieve the Distance
.getDirections();
return directions.routes[0].legs[0].distance.value/1609.34;
}
Have you tried using a try-catch block around directions.routes[0].legs[0].distance.value ?
try{
return directions.routes[0].legs[0].distance.value/1609.34;
}
catch (e){
console.log("error",e)
}
or you could try something like this
alert(directions);
alert(directions.routes[0]);
alert(directions.routes[0].legs[0]);
alert(directions.routes[0].legs[0].distance);
alert(directions.routes[0].legs[0].distance.value);
and so on...to find out which one comes up as undefined the first. That might help you to debug the issue.
Enable Direction Api
1)Go to "google cloud platform"
2)go to "Api and services"
3)search for "direction api" and enable it
The directions service is subject to a quota and a rate limit. Check the return status before parsing the result.
For lots of distances (or at least more than 10), look at the DistanceMatrix.
I'm able to run the script from the Script editor, but not from spreadsheet. The error is "unable to read property legs" when the function is called from spreadsheet. But the property is in place when called from Script editor and contain correct values.
You probably need to use WEB API and have API KEY:
Google Apps Script - How to get driving distance from Maps for two points in spreadsheet

Meteor realtime game - match two players according to their score?

I want to build a realtime quiz game which randomly matches two players (according to their winning rate if they are logged in). I've read through the book Discover Meteor and have a basic understanding of the framework, but I just have no idea of how to implement the matching part. Anyone know how to do that?
if you want to match users who have scores close to each other, you can do something like this : mongodb - Find document with closest integer value
The Meteor code for those Mongo queries is very similar, but there are some subtle differences that are kind of tricky. In Meteor, it would look something like this :
SP // "selected player" = the User you want to match someone up with
var score = SP.score; // selected player's score
var queryLow = {score: {$lte:score},_id:{$ne:SP._id}};
var queryHigh = {score:{$gte:score},_id:{$ne:SP._id}};
// "L" is the player with the closest lower score
var L=Players.findOne(queryLow,{sort:{score:-1},limit:1});
// "H" is the player with the closest higher score
var H=Players.findOne(queryHigh,{sort:{score:1},limit:1});
so, now you have references to the players with scores right above and right below the 'selected player'. In terms of making it random, perhaps start with a simple algorithm like "match me with the next available player who's score is closest" , then if it's too predictable and boring you can throw some randomness into the algorithm.
you can view the above Meteor code working live here http://meteorpad.com/pad/4umMP4iY8AkB9ct2d/ClosestScore
and you can Fork it and mess about with the queries to see how it works.
good luck! Meteor is great, I really like it.
If you add the package peppelg:random-opponent-matcher to your application, you can match together opponents like this:
On the server, you need to have an instance of RandomOpponentMatcher like this:
new RandomOpponentMatcher('my-matcher', {name: 'fifo'}, function(user1, user2){
// Create the match/game they should play.
})
The function you pass to RandomOpponentMatcher will get called when two users been matched to play against each other. In it, you'll probably want to create the match the users should play against each other (this package does only match opponents together, it does not contain any functionality for playing games/matches).
On the client, you need to create an instance of RandomOpponentMatcher as well, but you only pass the name to it (the same name as you used on the server):
myMatcher = new RandomOpponentMatcher('my-matcher')
Then when the users is logged in and which to be matched with a random opponent, all you need to do is to call the add method. For example:
<template name="myTemplate">
<button class="clickMatchesWithOpponent">Match me with someone!</button>
</template>
Template.myTemplate.events({
'click .clickMatchesWithOpponent': function(event, template){
myMatcher.add()
}
})
When two different logged in users has clicked on the button, the function you passed to RandomOpponentMatcher on the server will get called.
One implementation might be as follows:
A user somehow triggers a 'looking for game' event that sets an attribute on user.profile.lookingForGame to true. The event then makes a call to a server side Meteor method which queries for all other online users looking for games.
From there you it really depends on how you want to handle users once they 'match'.
To determine all online users, try using the User Status package:
https://github.com/mizzao/meteor-user-status
Once added, any online user will have an attribute in the profile object of 'online'. You can use this to query for all online users.

Biztalk Preload output message before Map transform

I have 2 correlated incoming messages from 2 different systems (SystemA and SystemB) and I just want to basically copy over a couple fields from the SystemA message to the SystemBmessage.
So my Construct Message shape looks like this:
The Message Assignment shape just has this code inside it:
xmlIncomingNoAttachHolder = new System.Xml.XmlDocument();
xmlIncomingNoAttachHolder = msgMultiPartInNoAttachment.BodySegments;
// assigning the SsytemB version (no attachment) first.
// Also, since we are only copying a couple fields, this can serve as the base.
msgComboWithAttach = xmlIncomingNoAttachHolder;
msgComboWithAttach(XMLNORM.TargetCharset) = "UTF-8";
The map then just has the 2 input (SystemA schema and SystemB schema) ORU messages on left and the output ORU message on the right, which also shares the same schema as the SystemB input message.
My hope was that I could just use the message assignment code above to assign the Output msgComboWithAttach message, then use the mapper to map over the few fields that we need from the SystemA message to the SystemB message.
But it seems that as soon as I apply the map, it clears the pre-loaded msgComboWithAttach message before performing the transform and then applies the map. The resulting message then contains ONLY those fields that are copied over in the map and none of the other segments/fields that were assigned in the message assignment pre-load.
Is this expected behaviour, in which case, I would have to do a Mass-Copy on all the segments in the Map? Or is there a way to pre-load/copy the message like I want and then only Map a couple fields over?
Yes, that is the expected behavior since the transform will create a new message. You cannot use Xslt to modify a document in that way.
Dijkgraaf's solution will work. As an alternative, you can use the Orchestration xpath() function to read and set specific values in Message. See: http://msdn.microsoft.com/en-us/library/ee268159(v=bts.10).aspx
Yes, that is expected behaviour.
What you want to do is
Distinguish the fields in the schema(s) (target and source, in your case they may be the same one if I understand what you are saying).
Have the map first making sure that your map creates the fields you want to populate with some dummy values.
Have an assignment shape after that just has one line for each of the fields in the format msgDestination.record.field = msgSource.record.field; (Note: you might have multiple levels of records).
This works only for non-reoccurring fields. For reoccurring fields you need to use a multi-part map instead.

Framebuster with exceptions

I have a question about writing a frame-buster-buster. I have already read Frame Buster Buster ... buster code needed but I need an extra tweak.
My content from my blog at [http://my_domain.c0m/blog] is being displayed at another site showing three "views". One view is a feed and doesn't particulary bother me. The other two bother me and I wish to break both. I also want to permit exceptions of domains with permission to frame.
In one view, it appears the the content from the top of my html of the top of my blog is first copied to create a "snapshot" [http://the_other_domain.c0m/copy_of_blog] then that copy is framed in [http://the_other_domain.c0m/ ]. So, in this case, the 'child' copy are both hosted at [http://the_other_domain.c0m/] . Google translate does a similar thing-- but I find this ok. So, I would like to break this frame while also permitting exceptions for google and also for people who have made a copy to their pcs and would like to view in a utility that might frame.
In the other view, it appears the content from my site is framed. So in this case [http://my_domain.c0m/blog_post] is framed by [http://the_other_domain.c0m/]. I would like to bust out of this frame. However, my difficulty is that I can't figure out how to do so while keeping the exceptions for google translate or individual pc users frames at home.
My solution so far (I am not particularly familiar with javascript. So, please don't laugh too hard at the redundancy and lack of knowledge):
I was able to bust the first frame using:
<SCRIPT type="text/javascript" >
var topWindow = String(top.location)
var topWord=topWindow.split("/")
var selfWindow = String(self.location)
var selfWord=topWindow.split("/")
var correctLocation ="http://my_domain.c0m/blog"
var correctWord2="my_domain.c0m"
var http="http:"
if( ( (topWord[2] != correctWord2) || (selfWord[2] != correctWord2) )
&& (topWord[2] != 'translate.googleusercontent.com' ) && (topWord[0] == http ) ){
document.write("message expressing my opinion about the asshattery going in here.]" )
setTimeout("redirect_after_pause()",8000)
}else{
//document.write("<p><font color='purple'>Hi there! Javascript is working.</font> </p> " )
}
function redirect_after_pause() {
var correctLocation ="http://my_domain.c0m/blog"
top.location=correctLocation
}
I know this is inefficient. But it works and achieves my goal of making an exception for a) translations at googlecontent which my readers in france requested and b) cases where a user is framing in a utility that downloads to their pc (which I think has uri's beginning with "FILE:".
Now the difficulty: This does not work for the view where content hosted at my domain is framed at the other domain. I believe I have tracked the problem down to var topWindow = String(top.location) not being permitted in my child window. In principle, this would work:
<script type="text/javascript">
if(top != self) top.location.replace(location);
However, I think it screws up the use of google translate which uses a top frame that holds their translation of my content also hosted at [http://translate.google.com]. I suspect it similarly screws up readers that might display a local copy on someones pc if that copy is displayed in a frame.
If someone can guide me toward a solution I can implement to break both frames while permitting my exception
BTW: It does appear that the site in question is using a framebuster. I poked around and found this inside their /static/common.js?1345250291 code:
enable_iframe_buster_buster:function(){var a=this,b=0;window.onbeforeunload=function(){b++};clearInterval(this.locks.iframe_buster_buster);this.locks.iframe_buster_buster=setInterval(function(){0<b&&(b-=2,a.flags.iframe_story_locations_fetched&&!a.flags.iframe_view_not_busting&&_.contains(["page","story"],a.story_view)&&NEWSBLUR.reader.active_feed&&($(".NB-feed-frame").attr("src",""),window.top.location="/reader/buster",$(".task_view_feed").click()))},1)},disable_iframe_buster_buster:function(){clearInterval(this.locks.iframe_buster_buster)}
That's deep inside some particulary dense javascript. Whatever it does it doesn't seem to affect my ability to bust the frame for the case where my content is copied and hosted at [http://the_other_domain.c0m/]. I haven't yet fully explored whether it busts simple framebusters because earlier I only recently recognized that " var topWindow = String(top.location) " was forbidden in the child frame with a different domain from the parent frame.
Whether or not the frame-buster is present, I'd like help with solutions here. I know that if one site is now framing my content in this way it is only a matter of time before the obnoxious technique catches on and I would like to code in solutions that bust both methods gracefully while providing myself with exceptions. Thanks in advance.

Resources