在Leaflet Popup中显示图像

时间:2012-05-13 22:34:04

标签: javascript ajax json leaflet

我正在尝试使用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();

有什么建议吗?

1 个答案:

答案 0 :(得分:10)

标记的bindPopup方法只是将HTML内容作为字符串,因此您还需要用引号括住标记 - 例如

marker1.bindPopup( "<img src=" + icon_url + "/> Current temperature in " + location + " is: " + temp_f)

应该适合你。