我有一个 Javascript 场景可以运行,它在控制台中给了我一个结果。在这种情况下,我需要插入 5 次一对不同的坐标(每次)。如果我使用不同的坐标(每次将它们插入到不同的变量中)复制粘贴相同的代码 5 次,则它不会运行。下面,我在 Jsfiddle 中尝试相同的操作时,使用不同的坐标放置了两次相同的代码。
//first pair of coordinates:
let x= 38.041242 ,y= 23.679595
let myString = `https://maps.googleapis.com/maps/api/streetview?location=${x},${y}&size=300x300&pitch=90`
getBase64FromImageUrl(myString);
console.log(x,y);
//second pair of coordinates:
let z= 38.041310 ,f= 23.679684
let myString = `https://maps.googleapis.com/maps/api/streetview?location=${z},${f}&size=300x300&pitch=90`
getBase64FromImageUrl(myString);
console.log(z,f);
最佳答案
我怀疑 @ThatBrianDude 和 @Archer 已经声明您收到错误,因为您多次定义变量 myString 。我还建议您创建一个对象数组,而不是一遍又一遍地复制粘贴代码。
// Array of coordinates to run through.
let coordinates = [{x: 38.041242, y: 23.679595, {x: 38.041310, y: 23.679684}];
// List of images.
let images = coordinates.map((coordinate) => {
// URL based on coordinates.
return getBase64FromImageUrl(`https://maps.googleapis.com/maps/api/streetview?location=${coordinate.x},${coordinate.y}&size=300x300&pitch=90`);
});
关于javascript - 在 Javascript 中多次运行命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48301282/