开发者

twitter geocode to google maps

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?


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);
}


(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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜