我正在尝试使用wunderground的api,Leaflet和Cloudmade将天气图标显示在地图标记中。我已经显示了文本和带有图标图像的变量,但是我不确定如何显示它。这是我的代码:
jQuery(document).ready(function($) { $.ajax({ url: "http://api.wunderground.com/api/cd48ac26fb540679/conditions/q/pws:KCASANFR128.json", dataType: "jsonp", success: function(parsed_json) { var location = parsed_json['current_observation']['observation_location']['city']; var temp_f = parsed_json['current_observation']['temp_f']; var icon = parsed_json['current_observation']['icon_url']; marker1.bindPopup("Current temperature in " +location+ " is: " + temp_f).openPopup(); } }); });
我尝试了一下但没有成功:
marker1.bindPopup( <img src=icon> "Current temperature in " +location+ " is: " + temp_f).openPopup();
有什么建议?
标记的bindPopup方法仅将HTML内容作为字符串,因此您还需要在标记周围加上引号-类似于
marker1.bindPopup( "<img src=" + icon_url + "/> Current temperature in " + location + " is: " + temp_f)
应该为您工作。