Google Static Maps API与jade动态链接

时间:2017-11-25 16:22:02

标签: javascript node.js pug google-static-maps

有没有办法让Google Static Maps API在pug(jade)模板中动态化?

例如,

img.img-responsive.img-rounded(src='http://maps.googleapis.com/maps/api/staticmap?center=52.241770, -0.900181&zoom=17&size=400x350&sensor=true&markers=52.241770, -0.900181&scale=2&key=API_KEY')

有效但

img.img-responsive.img-rounded(src='http://maps.googleapis.com/maps/api/staticmap?center={location.coords.lng},{location.coords.lat}&zoom=17&size=400x350&sensor=true&markers={location.coords.lng},{location.coords.lat}&scale=2&key=API_KEY')

没有。

2 个答案:

答案 0 :(得分:1)

使用引号怎么样?

img.img-responsive.img-rounded(src="http://maps.googleapis.com/maps/api/staticmap?center="  + location.coords.lng + "," + location.coords.lat + "&zoom=17&size=400x350&sensor=true&markers=" + location.coords.lng + "," + location.coords.lat + "&scale=2&key=API_KEY")

答案 1 :(得分:1)

尝试template literal

img.img-responsive.img-rounded(src=`http://maps.googleapis.com/maps/api/staticmap?center=${location.coords.lng},${location.coords.lat}&zoom=17&size=400x350&sensor=true&markers=${location.coords.lng},${location.coords.lat}&scale=2&key=API_KEY`)