admin管理员组文章数量:1404353
I am trying to pass a Javascript variable into a URL, but there is some sort of syntax error within it.
function initMap() {
var jsonData = { $tourArray }
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 4,
center: {
lat: jsonData.CenterLat,
lng: jsonData.CenterLon,
},
})
var kml = jsonData.KmlFile
var src = '/?= + kml'
var kmlLayer = new google.maps.KmlLayer(src, {
map: map,
})
}
The variable var kml
is basically the kml file name which is stored on the server within the folder KML and I am trying to access that file in order to add a KML layer on my google map.
The URL syntax seems to be incorrect.
I am trying to pass a Javascript variable into a URL, but there is some sort of syntax error within it.
function initMap() {
var jsonData = { $tourArray }
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 4,
center: {
lat: jsonData.CenterLat,
lng: jsonData.CenterLon,
},
})
var kml = jsonData.KmlFile
var src = 'http://www.example./KML/?= + kml'
var kmlLayer = new google.maps.KmlLayer(src, {
map: map,
})
}
The variable var kml
is basically the kml file name which is stored on the server within the folder KML and I am trying to access that file in order to add a KML layer on my google map.
The URL syntax seems to be incorrect.
Share Improve this question edited Aug 15, 2017 at 10:39 geocodezip 161k14 gold badges226 silver badges254 bronze badges asked Aug 15, 2017 at 8:56 Farhan HabibFarhan Habib 1534 silver badges13 bronze badges 5- How to insert javascript variables into a URL : stackoverflow./questions/17734343/… – Jixone Commented Aug 15, 2017 at 8:58
- can you print what's their in kml ? – marvel308 Commented Aug 15, 2017 at 8:58
- Possible duplicate of How to insert javascript variables into a URL – DarthJDG Commented Aug 15, 2017 at 8:59
- I had checked that question before, but the solution doesnt work in my case, According to that my url should bee "example./KML/?=" + kml; but this doesnt work as well . – Farhan Habib Commented Aug 15, 2017 at 9:02
- The names stored in the kml files are like this "T12_Zentral_Schweiz.kml" . – Farhan Habib Commented Aug 15, 2017 at 9:10
1 Answer
Reset to default 5You missed it.
var src = "http://www.example./KML/?=" + kml;
If you're using ES6, then template literals makes it even cleaner.
var src = `http://www.example./KML/?=${kml}`
本文标签: webHow to make a URL with javascript variableStack Overflow
版权声明:本文标题:web - How to make a URL with javascript variable? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744793188a2625416.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论