如何确定推文的位置(坐标)
我正在使用 jQuery 以 json 格式检索和显示有关 2 个足球队的推文。 我目前正在输出文本和用户 ID,但我计划在谷歌地图上绘制这些推文。但首先我需要获取推文的位置。关于如何实现这一目标的任何想法。
到目前为止的基本代码如下;
<script type="text/javascript">
$(document).ready(function(){
var team1, team2;
team1 = '<?php echo $_GET["team1"]; ?>';
team2 = '<?php echo $_GET["team2"]; ?>';
var url1="http://search.twitter.com/search.json?q=%23"+team1+"&callback=?";
var url2="http://search.twitter.com/search.json?q=%23"+team2+"&callback=?";
$.getJSON(
url1,function(results){ // get the tweets
var res1 = results.results[0].text;
var userID1 = results.results[0].from_user_id;
$("#last-tweet1").html(res1 + "<p>user id: " + userID1); // get the first tweet in the response and place it inside the div
});
$.getJSON(
url2,function(results){ // get the tweets
var res2 = results.results[0].text;
var userID2 = results.results[0].from_user_id;
$("#last-tweet2").html(res2 + "<p>user id: " + userID2 + "</p>"); // get the first tweet in the response and place it inside the div
});
I am using jQuery to retrieve and display tweets regarding 2 football teams in json format.
I am currently outputing the text and user ID but I plan to plot these tweets on a google map. But first I need to grab the location of the tweets. any ideas on how to achieve this.
The basic code so far is below;
<script type="text/javascript">
$(document).ready(function(){
var team1, team2;
team1 = '<?php echo $_GET["team1"]; ?>';
team2 = '<?php echo $_GET["team2"]; ?>';
var url1="http://search.twitter.com/search.json?q=%23"+team1+"&callback=?";
var url2="http://search.twitter.com/search.json?q=%23"+team2+"&callback=?";
$.getJSON(
url1,function(results){ // get the tweets
var res1 = results.results[0].text;
var userID1 = results.results[0].from_user_id;
$("#last-tweet1").html(res1 + "<p>user id: " + userID1); // get the first tweet in the response and place it inside the div
});
$.getJSON(
url2,function(results){ // get the tweets
var res2 = results.results[0].text;
var userID2 = results.results[0].from_user_id;
$("#last-tweet2").html(res2 + "<p>user id: " + userID2 + "</p>"); // get the first tweet in the response and place it inside the div
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
每个结果对象都有一个
geo
元素。不幸的是,大多数推文都没有附加位置信息,因此您找不到很多。Each result object has a
geo
element. Unfortunately the majority of tweets don't have location information attached so you will not find many.