使用JavaScript获取Google地图上显示的所有推文时遇到麻烦
trouble getting all the tweets shown on the google map using javascript
你好,我试图将一些推文放在谷歌地图上,首先使用js-placemaker从推文的文本中提取位置,这是雅虎的网络服务,用于从任何类型的数据中对文本进行地理定位。
问题是我在地图上放置了不同的标记,但我只收到来自 Twitter resutlts 回调的最后一条推文,并且在地图上的每个标记上都看到了相同的profile_img_url。我也无法让信息窗口工作。
function codeAddress(){
var geocoder = new google.maps.Geocoder();;
var mapOptions = {
center: new google.maps.LatLng(35.74651,-39.46289),
zoom: 2,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
// added this
var bounds = new google.maps.LatLngBounds();
// create the map
var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
$.getJSON("http://search.twitter.com/search.json?q=%23euronews&rpp=10&include_entities=true&result_type=mixed&callback=?", function (data) {
$.each(data.results, function (i, item) {
var screen_name = item.screen_name;
var contentString=screen_name;
var img = item.profile_image_url;
var text=item.text;
var profile_img=item.profile_image_url;
var url=(item.entities.urls.length > 0 ? item.entities.urls[0].url : '');
// var latitude,longitude;
Placemaker.getPlaces(text,
function(o){
console.log(o);
var latitude=o.match.place.centroid.latitude,
longitude=o.match.place.centroid.longitude;
var myLatLng = new google.maps.LatLng(latitude, longitude);
var marker = new google.maps.Marker({
icon: img,
title: screen_name,
map: map,
position: myLatLng
});
var infowindow = new google.maps.InfoWindow({
content: contentString
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
});
bounds.extend(myLatLng);
});
});
// map.fitBounds(bounds);
});
}
与这个类似问题相同的根本问题。 可以通过在异步回调上适当使用函数闭包来解决。
信息窗口的问题是没有内容(screen_name和内容字符串未定义)。
相关文章:
- BrowserId登录请求在文档加载时被调用
- 将子文档推送到父数组时遇到问题
- 当在文档中拖动mouseup/mouseleve时,我想调用我的Ajax请求
- 当所有输入文本字段都为空时,禁止表单提交,但当jquery中的任何字段不为空时允许提交
- JS触发器值检查在文档加载后添加到页面的元素在加载时更改AND
- 更改所选选项更改时的页眉和隐藏文本字段
- 在文档加载Tampermonkey时单击事件激发
- jQuery模糊时验证文本字段
- 如何在输入文本字段中输入10个字符时自动提交表单
- 函数不't在jquery文档就绪时执行
- 在提交时影响其他文档
- 单击按钮时如何聚焦下一个文本字段
- 使用Twitter API进行推文时出现重复状态错误
- 如何在单击按钮时将页面中所有文本字段中的数据更改为大写
- 在粘贴到文本字段Jquery时检查并突出显示不支持的特殊字符
- 如何编写单个 Jquery 函数以在文档更改和就绪事件时触发
- 使用JavaScript获取Google地图上显示的所有推文时遇到麻烦
- Codebird 发布推文时出现问题
- 尝试解码 AES-128-CBC 密文时获取空字符串
- 从Twitter api 1.1获取推文时出错