how to get trends from twitter about a specific location - twitter

I'm trying to get the twitter trends for a specific location say "Bristol" from UK for my application.
Problem is that right now we can get the Trends for only countries and some cities in US as mentioned in twitter API. But i'm just wondering how the site like
http://trendsmap.com/local/gb/bristol
is getting the trends in most of the countries and cities even though they were not listed in twitter trends api.
Please help in figuring out this
Regards,
Sukumar

I put together a nice JS fiddle that should answer all your questions when it comes to dealing with the Twitter API. The webapp grabs the trending locales, and allows you to drill down to the trending topics, and then see the Tweets within.
I also included a standard Twitter search submission box, so in a weird way, this is a barebones Tweetdeck client for you to examine. Also, to push the adaption of the new Jquery libraries, I have used 1.91 which utilities the new live.bind click event syntax.
Enjoy
http://jsfiddle.net/jdrefahl/5M3Gn/
function searchTwitter(query) {
$.ajax({
url: 'http://search.twitter.com/search.json?' + jQuery.param(query),
dataType: 'jsonp',
success: function (data) {
var tweets = $('#tweets');
tweets.html('');
for (res in data['results']) {
tweets.append('<div>' + data['results'][res]['from_user'] + ' wrote: <p>' + data['results'][res]['text'] + '</p></div><br />');
}
}
});
}
$(document).ready(function () {
function getTrendsByID(id) {
$.ajax({
url: 'http://api.twitter.com/1/trends/' + id + '.json',
dataType: 'jsonp',
success: function (data) {
$.each(data[0].trends, function (i) {
});
}
});
};
function getLocales() {
$.ajax({
url: 'https://api.twitter.com/1/trends/available.json',
dataType: 'jsonp',
success: function (data) {
var locales = $('ul#locales');
locales.html('');
$.each(data, function (i) {
localeID[i] = data[i].woeid;
$('ul#locales').append('<li>' + data[i].name + '</li>');
});
}
});
};
function getTrends(id) {
$.ajax({
url: 'https://api.twitter.com/1/trends/' + id + '.json',
dataType: 'jsonp',
success: function (data) {
var trends = $('ul#currentTrends');
trends.html('');
$.each(data[0].trends, function (i) {
$('ul#currentTrends').append('<li>' + data[0].trends[i].name + '</li>');
});
}
});
};
// Event Handlers
$(document).on("click", "#locales li", function () {
var $this = $(this);
var localesHdr = $('#currentTrendsCont h3');
var tweets = $('#tweets');
var trendsHdr = $('#tweetsCont h3');
trendsHdr.html('');
tweets.html('');
localesHdr.html('');
$('#currentTrendsCont h3').html($this.text());
getTrends(localeID[$this.index()]);
});
$(document).on("click", "#currentTrends li", function () {
var $this = $(this);
var trendsHdr = $('#tweetsCont h3');
trendsHdr.html('');
$('#tweetsCont h3').html($this.text());
var params = {
q: $this.text(),
rpp: 10
};
searchTwitter(params);
});
$('#submit').click(function () {
var trendsHdr = $('#tweetsCont h3');
var trends = $('#currentTrends');
var local = $('#currentTrendsCont h3');
local.html('');
trendsHdr.html('');
trends.html('');
$('#tweetsCont h3').html('search query: '+$('#query').val());
var params = {
q: $('#query').val(),
rpp: 10
};
searchTwitter(params);
});
// Globals
var localeID = new Array();
// Init!
getLocales();
});

Take a look at the documentation here

Related

jeasyui: how to get queryparams in another page by clientside

jeasyui: how to get queryparams in another page by clientside
page 1(root.html):
$.ajax({
type: "get",
async: true,
url: "/ashx/product/root.ashx",
dataType: 'json',
success: function (res) {
var o = $('#tb');
for (i = 0; i < res.length; i++) {
o.tabs('add', {
title: res[i].Name + '-' + res[i].PkId,
href: '/html/usr/node.html', queryParams: { 'id': res[i].id }
});
o.tabs('select', 0);
}
}
});
page 2(node.html):
<script>
// how to get queryParams from page root.html here in javascript.
alert();
</script>
Use JSONP
JQUERY
$.ajax({
url:"node.html.html",
dataType: 'jsonp',
success:function(json){
alert("Success");
},
error:function(){
alert("Error Message");
}
});
node.html ( note im using php )
<?php
$arr = array("param1",
"param2",
array("param3","param4"));
$arr['name'] = "response";
echo json_encode($arr);
?>

jquery UI Autocomplete with stored list

Hi I'm using jQuery UI Autocomplete and want do something like this: I want to get the list with AJAX when length=3 and this work great it populate the drop-down. Next I want when the length is >3 to use the returned list from the AJAX and filter it. But it give the same list not filtered.
$( ".selector" ).autocomplete({
source:function(request, response) {
var str_req = request.term;
if(str_req.length==3) {
$.ajax({
url: "/?search=1",
type: "GET",
dataType: "json",
data: {term: request.term},
success: function (data) {
auto_data=data;
response(data);
}
});
} else{
return response(auto_data);
}
},
minLength: 3,
select: function( event, ui ) {
console.log( "Selected: " + ui.item.value + " aka " + ui.item.id );
}
});
I would simply set the min to 1 and do a comparison in the source.
$(".selector").autocomplete({
source:function(request, response) {
var str_req = request.term;
if(str_req.length < 3) {
// Send your list back, if it was stored in 'myData'
response(myData);
} elseif(str_req.length==3) {
$.ajax({
url: "/?search=1",
type: "GET",
dataType: "json",
data: {term: str_req},
success: function (data) {
auto_data=data;
response(data);
}
});
} else{
response(auto_data);
}
}
},
minLength: 1,
select: function(event, ui) {
console.log( "Selected: " + ui.item.value + " aka " + ui.item.id );
}
});
You could also do this as a Switch statement:
var str_req = request.term;
switch(true){
case str_req.length < 3:
// Send your list
break;
case str_req.length == 3:
// Perform AJAX & return results
break;
default:
// All other options
response(auto_data);
}

get instance of map in jquery ui map

i want to make the markers clustered with markerClusterer but i cannot get the map instance with jquery ui map . js
tried:
var map = $('#map_canvas').gmap('getMap');
or
var map = $('map_canvas').gmap('get', 'map');
and after:
var markerCluster = new MarkerClusterer(map, allMarkers);
but with errors
Thank you
Tried this . No Errors but no clusters...
$('#map_canvas').gmap({ 'callback': function () {
var self = this;
$.getJSON('Data/markers.json', function (data) {
$.each(data.markers, function (i, marker) {
self.addMarker({ 'position': new google.maps.LatLng(marker.latitude,marker.longitude)}).click(function () {
$.ajax({
type: "GET",
url: "/LocoMap/LocoMap/InfoMobilePartialView/",
data: { latitude: marker.latitude, longitude: marker.longitude},
success: function (data) {
$("#marker-info").remove();
$(document.body).append("<div id='marker-info' data-role ='page'> </div>");
var $contentDiv = $("#marker-info");
$contentDiv.html(data).trigger('create');
$.mobile.changePage("#marker-info", { changeHash: false, type: "get", transition: 'pop',rel:"external" });
},
error: function (errorData) { onError(errorData); }
});
});
});
});
self.set('MarkerClusterer', new MarkerClusterer(this.get('map'), this.get('markers')));
}});
$('#map_canvas').gmap({'zoom': 2, 'disableDefaultUI':true}).bind('init', function(evt, map) {
$.getJSON( 'Data/markers.json', function(data) {
$.each( data.markers, function(i, m)
$('#map_canvas').gmap('addMarker', { 'position': new google.maps.LatLng(m.latitude, m.longitude), 'bounds':true } );
});
});
$('#map_canvas').gmap('set', 'MarkerClusterer', new MarkerClusterer(map,$(this).gmap('get', 'markers')));
});
with no errors and no clusters
it seems **$(this).gmap('get', 'markers')));** returns Array[0]

jQueryUI Autocomplete - Multiple controls - One function

I am using the jQueryUI autocomplete, have used it many times before, but I now have a more complex requirement.
I have a variable amount of Autocomplete fields to setup, using a JSON datasource and want to use an $().each to set these up. The problem appears to be the data: property of the AJAX call is always defaulting to values the final Autocomplete I setup.
$('[id$=CheckMethod]').each(function(index) {
if ($(this).val() === 'List') {
fieldToSetup = ($(this).attr('id').replace('txt',''));
fieldToSetup = left(fieldToSetup,(fieldToSetup.length - 11));
alert(fieldToSetup);
$('#txt' + fieldToSetup + 'CodeRoom' + escape(inRoomID)).autocomplete({
source: function (request, response) {
var src,
arrayData;
src = 'AJAXCheckCode.asp?actionType=List&GUID=' + $('#txtGUID').val();
$.ajax({
url: src,
datatype: 'json',
data: 'inCode=' + request.term + '&inType=' + $(this).attr('id'),
success: function (outData) {
arrayData = $.parseJSON(outData);
response($.map(arrayData, function (item) {
var theLabel = (item.Notes.length > 0) ? item.TheCode + ' - ' + item.Notes : item.TheCode;
return {
label: theLabel,
value: item.TheCode
};
}));
}
});
},
minLength: 1,
open: function (event, ui) {
$(".ui-slider-handle ui-state-default ui-corner-all").hide();
$(".ui-autocomplete.ui-menu").width(400);
$(".ui-autocomplete.ui-menu").css('z-index', 1000);
},
close: function (event, ui) {
$(".ui-slider-handle ui-state-default ui-corner-all").show();
},
focus: function (event, ui) {
return false;
},
select: function (event, ui) {},
search: function (event, ui) {
}
});
}
});//each CheckMethod
This code results in the 1st Autocomplete field using the inType parameter from the last field setup.
I'd rather not code for a maximum of 4 x 6 Autocomplete fileds and am trying to create one function to setup all the fields, is this possible?
Therefore my AJAX URL for my 1st Autocomplete looks like this
http://foo.com/AJAXCheckCode.asp?actionType=List&GUID={838138D6-A329-40F1-924B-58965842ECF8}&inCode=es&inType=A3&_=1335875408670
when "inType" should actually be A2, not A3 which is the last item of the outer $.each()
Hope this makes some sense!
Solved in the end by adding a class to the text box and then using live() on any text box with the given class that hasn't been bound before...works a charm
$('.foo:not(.ui-autocomplete-input)').live('focus', function(){
var fieldToReSource = ($(this).attr('id').replace('txt',''));
fieldToReSource = left(fieldToReSource,(fieldToReSource.length - 5));
$(this).autocomplete({
source: function (request, response) {
var src,
arrayData;
src = 'AJAXCheckCode.asp?inType=' + fieldToReSource + '&actionType=List&GUID=' + $('#txtGUID').val();
$.ajax({
url: src,
datatype: 'json',
data: 'inCode=' + request.term,
success: function (outData) {
arrayData = $.parseJSON(outData);
response($.map(arrayData, function (item) {
var theLabel = (item.Notes.length > 0) ? item.TheCode + ' - ' + item.Notes : item.TheCode;
return {
label: theLabel,
value: item.TheCode
};
}));
}
});
},
minLength: 1,
open: function (event, ui) {
$(".ui-slider-handle ui-state-default ui-corner-all").hide();
$(".ui-autocomplete.ui-menu").width(400);
$(".ui-autocomplete.ui-menu").css('z-index', 1000);
},
close: function (event, ui) {
$(".ui-slider-handle ui-state-default ui-corner-all").show();
},
focus: function (event, ui) {
return false;
},
select: function (event, ui) {
},
search: function (event, ui) {
}
});
});

Hot topics extraction from Twitter

I am building a website of finding and showing the hottest topics curretly on Twitter for my final project. Does anyone know how to extract the topics from the huge amount of tweets in the last week, or in a single day? I'm also wondering how to show the topics like a tag cloud on http://tweet3d.com/ and show the trend of each topic like http://trendistic.indextank.com/.
I really need your help since this final project dues at the end of this month. My partner asks me to use Flash Builder, I'm also learning to use that. Thanks guys.
Additional Info(11/20/2011): after I do a search on Google, I come to this paper: comparing Twitter and traditional media using Topic Model,you may access it with this link: paper, but I cannot understand the model since I lack the related background.
I am not so familiar with the Twitter API, but maybe this could help:
https://dev.twitter.com/docs/api/1/get/trends/current
I put together a nice JS fiddle that should answer all your questions when it comes to dealing with the Twitter API. The webapp grabs the trending locales, and allows you to drill down to the trending topics, and then see the Tweets within.
I also included a standard Twitter search submission box, so in a weird way, this is a barebones Tweetdeck client for you to examine. Also, to push the adaption of the new Jquery libraries, I have used 1.91 which utilities the new live.bind click event syntax.
Enjoy
http://jsfiddle.net/jdrefahl/5M3Gn/
function searchTwitter(query) {
$.ajax({
url: 'http://search.twitter.com/search.json?' + jQuery.param(query),
dataType: 'jsonp',
success: function (data) {
var tweets = $('#tweets');
tweets.html('');
for (res in data['results']) {
tweets.append('<div>' + data['results'][res]['from_user'] + ' wrote: <p>' + data['results'][res]['text'] + '</p></div><br />');
}
}
});
}
$(document).ready(function () {
function getTrendsByID(id) {
$.ajax({
url: 'http://api.twitter.com/1/trends/' + id + '.json',
dataType: 'jsonp',
success: function (data) {
$.each(data[0].trends, function (i) {
});
}
});
};
function getLocales() {
$.ajax({
url: 'https://api.twitter.com/1/trends/available.json',
dataType: 'jsonp',
success: function (data) {
var locales = $('ul#locales');
locales.html('');
$.each(data, function (i) {
localeID[i] = data[i].woeid;
$('ul#locales').append('<li>' + data[i].name + '</li>');
});
}
});
};
function getTrends(id) {
$.ajax({
url: 'https://api.twitter.com/1/trends/' + id + '.json',
dataType: 'jsonp',
success: function (data) {
var trends = $('ul#currentTrends');
trends.html('');
$.each(data[0].trends, function (i) {
$('ul#currentTrends').append('<li>' + data[0].trends[i].name + '</li>');
});
}
});
};
// Event Handlers
$(document).on("click", "#locales li", function () {
var $this = $(this);
var localesHdr = $('#currentTrendsCont h3');
var tweets = $('#tweets');
var trendsHdr = $('#tweetsCont h3');
trendsHdr.html('');
tweets.html('');
localesHdr.html('');
$('#currentTrendsCont h3').html($this.text());
getTrends(localeID[$this.index()]);
});
$(document).on("click", "#currentTrends li", function () {
var $this = $(this);
var trendsHdr = $('#tweetsCont h3');
trendsHdr.html('');
$('#tweetsCont h3').html($this.text());
var params = {
q: $this.text(),
rpp: 10
};
searchTwitter(params);
});
$('#submit').click(function () {
var trendsHdr = $('#tweetsCont h3');
var trends = $('#currentTrends');
var local = $('#currentTrendsCont h3');
local.html('');
trendsHdr.html('');
trends.html('');
$('#tweetsCont h3').html('search query: '+$('#query').val());
var params = {
q: $('#query').val(),
rpp: 10
};
searchTwitter(params);
});
// Globals
var localeID = new Array();
// Init!
getLocales();
});

Resources