EXIF "initMap is not a function".js不起作用



我知道这个问题以前被问过很多次,但我似乎找不到我的案例的答案。有些事情我没有看到,我提前道歉。我的任务是创建一个图像库,当我点击其中一个时,图像会变得更大,旁边会显示EXIF数据和照片拍摄的位置。

我提取了所有内容,只是位置没有显示,在控制台中我不断收到消息"initMap不是一个函数",错误指向HTML<!DOCTYPE html>中的第一行代码

我尝试过移动HTML中的<script src="https://maps.googleapis.com/maps/api/js?key=API_KEY&libraries=places&callback=initMap"" async="false"></script>位置。。。。没有成功。更改async="false"->async="defer"。按照之前提出的一个问题中的建议,从谷歌链接中删除callback=initMap

尝试在.js文件中的代码之后和之前调用该函数。我肯定错过了一些非常基本的东西,只是似乎找不到。

<div id="imageContainer"></div>
<div>
<div id="myModal" class="modal">
<img id="current" class="modal-content" >
<span class="close">&times;</span>
<pre id="exifResult"></pre>
<div id="map"></div>
</div>

let $modal = $('.modal')
let $img = $("#imageContainer img");
$img.click(function(){
$('.modal-content').attr('src', $(this).attr('src'));
$modal.css('display', 'block')
var imgCurrent = document.getElementById('current');
EXIF.getData(imgCurrent,function(){
let result = $('#exifResult')
let make = EXIF.getAllTags(this);
let exifData = Object.entries(make).map(([property, value]) => {
return `${property}: ${value}`;
})
result.text(exifData.join('n'));
let latDegree = this.exifdata.GPSLatitude[0].numerator;
let latMinute = this.exifdata.GPSLatitude[1].numerator;
let latSecond = this.exifdata.GPSLatitude[2].numerator;
let latDirection = this.exifdata.GPSLatitudeRef;
let latFinal = ConvertDMSToDD(latDegree, latMinute, latSecond, latDirection);
let lonDegree = this.exifdata.GPSLongitude[0].numerator;
let lonMinute = this.exifdata.GPSLongitude[1].numerator;
let lonSecond = this.exifdata.GPSLongitude[2].numerator;
let lonDirection = this.exifdata.GPSLongitudeRef;
let lonFinal = ConvertDMSToDD(lonDegree, lonMinute, lonSecond, lonDirection);

function initMap() {
var mapOptions = {
center: {lat: latFinal, lng: lonFinal},
zoom: 8
}
map = new google.maps.Map(document.getElementById('map'), {
mapOptions
});
}
});

function ConvertDMSToDD(degrees, minutes, seconds, direction) {
var dd = degrees + (minutes/60) + (seconds/3600);
if (direction == "S" || direction == "W") {
dd = dd * -1; 
}
return dd;
}
})

我将initMap()函数设置为全局函数,并用调用它

If(statement){ initMap() }

在CCD_ 7函数中。

$img.click(function() {
$('.modal-content').attr('src', $(this).attr('src'));
$modal.css('display', 'block');;
const imgCurrent = document.getElementById('current');
EXIF.getData(imgCurrent, function() {
const result = $('#exifResult')
const make = EXIF.getAllTags(this);
let exifData = Object.entries(make).map(([property, value]) => {
return `${property}: ${value}`;
})
result.text(exifData.join('n'));
let latFinal;
if (imgCurrent.exifdata.GPSLatitude && imgCurrent.exifdata.GPSLatitude.length > 0) {
const latDegree = imgCurrent.exifdata.GPSLatitude[0].numerator;
const latMinute = imgCurrent.exifdata.GPSLatitude[1].numerator;
const latSecond = imgCurrent.exifdata.GPSLatitude[2].numerator;
const latDirection = imgCurrent.exifdata.GPSLatitudeRef;
latFinal = ConvertDMSToDD(latDegree, latMinute, latSecond, latDirection);
}
let lonFinal;
if (imgCurrent.exifdata.GPSLongitudeRef && imgCurrent.exifdata.GPSLongitudeRef.length > 0) {
const lonDegree = imgCurrent.exifdata.GPSLongitude[0].numerator;
const lonMinute = imgCurrent.exifdata.GPSLongitude[1].numerator;
const lonSecond = imgCurrent.exifdata.GPSLongitude[2].numerator;
const lonDirection = imgCurrent.exifdata.GPSLongitudeRef;
lonFinal = ConvertDMSToDD(lonDegree, lonMinute, lonSecond, lonDirection);
}
if (latFinal && lonFinal) {
initMap(latFinal, lonFinal);
} else {
alert('Google Location Missing');
}
});

function ConvertDMSToDD(degrees, minutes, seconds, direction) {
var dd = degrees + (minutes/60) + (seconds/3600);
if (direction == "S" || direction == "W") {
dd = dd * -1; 
}
return dd;
}
})

function initMap(lonFinal,latFinal) {
var map = new google.maps.Map(document.getElementById('map'), {
center: {lat: lonFinal, lng: latFinal},
zoom: 10,
});
}

最新更新