Skip to content

Instantly share code, notes, and snippets.

@orfeomorello
Created May 27, 2011 16:58
Show Gist options
  • Save orfeomorello/995682 to your computer and use it in GitHub Desktop.
Save orfeomorello/995682 to your computer and use it in GitHub Desktop.
Call mashape API to get a valid token to invoke our Api Wrapper for static maps
var currentLocation;
var currentLatitude;
var currentLongitude;
/* Default map provider. You can select Bing,Facebook,Foursquare,Google,Ovi,Openstreetmap */
var provider="Google";
var textFromDatabase="";
var goNext=0;
function executeRequest()
{
$.ajax({
url : tokenUrl,
dataType : "jsonp",
jsonpCallback: "elaborateToken",
timeout : 700
});
}
function elaborateToken(data)
{
var localstreamerUrl ='http://www.localstreamer.com/mashape/staticimagemap/lat/'+currentLatitude+'/lng/'+currentLongitude+'/provider/'+provider+'?zoom=10&_token='+data.token;
$.getJSON(localstreamerUrl,{}, function(data)
{
if (data.imageUrl)
{
var imageUrl = data.imageUrl
var htmlCode = '<a href="#" class="css_tooltip">'+currentLocation+' <span><img src="'+imageUrl+'"></span></a>';
var match = new RegExp(currentLocation, "ig");
textFromDatabase = textFromDatabase.replace(match, htmlCode);
document.getElementById("content").innerHTML = textFromDatabase;
goNext=goNext+1;
if(pointsArray[goNext])
{
currentLocation = pointsArray[goNext][0];
currentLatitude = pointsArray[goNext][1];
currentLongitude = pointsArray[goNext][2];
executeRequest();
}
else
{
document.getElementById('pleasewait').style.display = 'none';
alert('Completed!');
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment