views:

324

answers:

2

Hi

Im trying to make this tutorial to work but Im having some difficulties.

http://woorkup.com/2009/12/26/how-to-play-with-google-maps-and-twitter-api/

When I run the loadFromTwitter function I get a javascript error. It says "invalid label".

The code so far is:

loadFromTwitter = function(lat,lng,r) {

    var url = 'http://search.twitter.com/search.json?geocode='
              +lat+'%2C'
              +lng+'%2C'+r
              +'km&callback=manage_response';
   var script = document.createElement('script');
   script.setAttribute('src', url);
   document.getElementsByTagName('head')[0].appendChild(script);
}

What am I doing wrong?

A: 

It's an error in the tutorial page, Francesca has somehow double-encoded the special characters. The %2c's should be commas and the & should be &.

loadFromTwitter = function(lat,lng,r) {

    var url = 'http://search.twitter.com/search.json?geocode='
              +lat+','
              +lng+','+r
              +'km&callback=manage_response';
   var script = document.createElement('script');
   script.setAttribute('src', url);
   document.getElementsByTagName('head')[0].appendChild(script);
}
Mike Williams
thx man! I checked out your profile and u seem to be some kind of google maps, javascript guru. very nice :) keep up the good work!
yazz
A: 

(I wanted to write this as a comment, but there wasn't enough room.)

Although that change gets you the info from Twitter, doing anything useful with it on a Google Map is rather trickier than suggested in that tutorial.

As mentioned in that tutorial, Twitter doesn't tell you the lat/lng values where it thinks the tweet came from, so you have to geocode the tweet.location yourself. You then discover that many tweet.location values are garbage. Presumably tweeters can write anything in that field.

For the tweets that do have valid locations, most of them are only accurate to the nearest city. You get lots of tweets in each city all of which geocode to exactly the same location at the centre of the city. There's no nice easy way to deal with that in Google Maps. It always ends up being very messy.

Also, you tend to get more tweets in the reply than the GClientGeocoder limit of calls per second, so you have to add delays between the geocode calls and add code to handle error 620.

Mike Williams
Yes, I discovered that fact when I got my loadfromtwitter function to work. A lot of data i garbage. I'v uploaded a test to http://www.varskaviata.nu/twittermap. Now Im thinking of maybe narrow the tweets to only show tweets that come from an Iphone.
yazz