Currently, I am extracting GPS data from an image using exifjs. My objective is to convert the latitude and longitude variables into a decimal variable as illustrated below:
<template lang="html">
<div class="upload-wrap">
<button class="btn">Choose a photo</button>
<input ref="fileinput" @change="onChange" id="file-input" type="file" accept="image/jpeg"/>
</div>
</template>
<script>
import EXIF from '../../node_modules/exif-js/exif'
export default {
methods: {
toDecimal(number) {
return number[0].numerator + number[1].numerator /
(60 * number[1].denominator) + number[2].numerator / (3600 * number[2].denominator);
},
onChange(image) {
var input = this.$refs.fileinput
if (image) {
EXIF.getData(input.files[0], function() {
var lat = EXIF.getTag(this, 'GPSLatitude');
var long = EXIF.getTag(this, 'GPSLongitude');
if (lat && long) {
var lat_dec = toDecimal(lat);
var long_dec = toDecimal(long);
// eslint-disable-next-line
console.log(lat_dec, long_dec);
}
else {
// No metadata found
clearFileInput(input);
alert("No GPS data found in image '" + input.files[0].name + "'.");
}
})
} else {
// eslint-disable-next-line
console.log(`No image selected?`);
}
},
// Clear file input if there's no exif data
clearFileInput(ctrl) {
ctrl.value = null;
}
}
}
</script>
Yet, I encountered the following error:
ReferenceError: toDecimal is not defined
I wonder if I am utilizing the correct syntax or missing something crucial?
Edit: I attempted to use this.toDecimal(lat);
but it led to
TypeError: this.toDecimal is not a function