Php 如何从JPEG EXIF数据中检索地理位置信息?
我正在用PHPGD库进行图像处理。刚才上帝出现了,告诉我我们可以从jpeg、tiff图像中检索exif数据。但是,他没有告诉我怎么做Php 如何从JPEG EXIF数据中检索地理位置信息?,php,geolocation,gd,exif,Php,Geolocation,Gd,Exif,我正在用PHPGD库进行图像处理。刚才上帝出现了,告诉我我们可以从jpeg、tiff图像中检索exif数据。但是,他没有告诉我怎么做 我试着上网,找到了一些关于检索数据的帖子。在我尝试获取地理位置数据之前,地球上的一切都很好。我找不到任何解决方案来获取这些数据。我在评论中提到过。现在我在办公桌前,我可以再详细阐述一下。不久前,我创建了一个函数来执行以下操作: // get geo-data from image function get_image_location($file) { i
我试着上网,找到了一些关于检索数据的帖子。在我尝试获取地理位置数据之前,地球上的一切都很好。我找不到任何解决方案来获取这些数据。我在评论中提到过。现在我在办公桌前,我可以再详细阐述一下。不久前,我创建了一个函数来执行以下操作:
// get geo-data from image
function get_image_location($file) {
if (is_file($file)) {
$info = exif_read_data($file);
if ($info !== false) {
$direction = array('N', 'S', 'E', 'W');
if (isset($info['GPSLatitude'], $info['GPSLongitude'], $info['GPSLatitudeRef'], $info['GPSLongitudeRef']) &&
in_array($info['GPSLatitudeRef'], $direction) && in_array($info['GPSLongitudeRef'], $direction)) {
$lat_degrees_a = explode('/',$info['GPSLatitude'][0]);
$lat_minutes_a = explode('/',$info['GPSLatitude'][1]);
$lat_seconds_a = explode('/',$info['GPSLatitude'][2]);
$lng_degrees_a = explode('/',$info['GPSLongitude'][0]);
$lng_minutes_a = explode('/',$info['GPSLongitude'][1]);
$lng_seconds_a = explode('/',$info['GPSLongitude'][2]);
$lat_degrees = $lat_degrees_a[0] / $lat_degrees_a[1];
$lat_minutes = $lat_minutes_a[0] / $lat_minutes_a[1];
$lat_seconds = $lat_seconds_a[0] / $lat_seconds_a[1];
$lng_degrees = $lng_degrees_a[0] / $lng_degrees_a[1];
$lng_minutes = $lng_minutes_a[0] / $lng_minutes_a[1];
$lng_seconds = $lng_seconds_a[0] / $lng_seconds_a[1];
$lat = (float) $lat_degrees + ((($lat_minutes * 60) + ($lat_seconds)) / 3600);
$lng = (float) $lng_degrees + ((($lng_minutes * 60) + ($lng_seconds)) / 3600);
$lat = number_format($lat, 7);
$lng = number_format($lng, 7);
//If the latitude is South, make it negative.
//If the longitude is west, make it negative
$lat = $info['GPSLatitudeRef'] == 'S' ? $lat * -1 : $lat;
$lng = $info['GPSLongitudeRef'] == 'W' ? $lng * -1 : $lng;
return array(
'lat' => $lat,
'lng' => $lng
);
}
}
}
return false;
}
此功能用于处理文件上载,例如:
if (($geo = get_image_location($_FILES['file']['tmp_name'])) && !empty($geo)) {
// upload file
} else {
// file does not appear to contain any location information
}
这应该给你一个好的开始。我的上帝对那些没有任何研究的帖子感到不快,他让我否决你的问题。赞美吧!哈哈。。我研究了[exif_read_data](),能够从中检索方向、缩略图和相机参数,但对地理位置数据无能为力。我无法获得太多关于exif地理位置检索的信息,因此无法进行任何研究。现在,印度和英国都是民主共和国,如果你愿意,你可以投反对票。再次感谢你抽出时间谢谢martin先生你的密码帮了我。。这正是我想要的。。再次感谢印度_/\_