简体   繁体   中英

Google Static Maps API dynamic links with jade

Is there a way to make Google Static Maps API links dynamic inside a pug(jade) template?

For example,

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')

works but

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')

does not.

那用引号呢?

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")

尝试使用模板文字

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`)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM