简体   繁体   English

如何从 Javascript 中的图像文件数据中读取地理位置

[英]How to read geo location from an image file data in Javascript

How to read geolocation data from an image file (JPG, JPEG, PNG, etc) in Javascript at the moment of loading the file onto web browser but before the actual upload (on the client side).如何在将文件加载到 web 浏览器但实际上传之前(在客户端)从 Javascript 中的图像文件(JPG、JPEG、PNG 等)读取地理定位数据。

There is a module called exif you could use like this:有一个名为exif的模块,您可以这样使用:

var ExifImage = require('exif').ExifImage;

try {
    new ExifImage({ image : 'myImage.jpg' }, function (error, exifData) {
        if (error)
            console.log('Error: '+error.message);
        else
            console.log(exifData); // Do something with your data!
    });
} catch (error) {
    console.log('Error: ' + error.message);
}

You can use Browserify to convert this npm module for use in the browser.您可以使用Browserify将此 npm 模块转换为在浏览器中使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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