Hi Stephen,
Could you please suggest me a code to display the number of images with GPS coordinates from the total number of images in the gallery?
Either so I can put it somewhere in the theme, or maybe this information could appear on the Gallery Stats page.
And maybe if I go a little further with the idea, maybe this information would be interesting for each album in the administration (e.g. in the right column).
I have already abandoned the idea of displaying a map with all images with GPS, because I think it would be very heavy on the server.
Display number of images with GPS
-
- Site Admin
- Posts: 94
- Joined: Tue Aug 14, 2018 6:33 pm
- Location: Huntington Beach, CA, USA
Re: Display number of images with GPS
The following loop will find images in the album that have gps data:
So far as performance is concerned I do not think this will add much to the processing. netPhotoGraphics caches the list of images and any image object that is instantiated. Since if you are showing a map of the album with image points the image list and all the images will have already been cached so it is just the above loop that will be added to the processing overhead.
Code: Select all
$count = 0;
$images = $album->getImages(0, 0, null, null, false);
$total_images = count($images);
foreach ($images as $an_image) {
$image = newImage($album, $an_image);
$lat = (string) $image->getGPSLatitude();
$long = (string) $image->getGPSLongitude();
if (!(empty($lat) || empty($long))) {
/* this image has geo data, so count it or whatever */
$count ++;
}
}
-Stephen
-
- Site Admin
- Posts: 94
- Joined: Tue Aug 14, 2018 6:33 pm
- Location: Huntington Beach, CA, USA
Re: Display number of images with GPS
You could also use an SQL query to get the count:
Code: Select all
$sql = 'SELECT count(*) FROM ' . prefix('images') . ' WHERE `albumid`=' . $album->id . ' and `gpslatitude` is not null and `gpslongitude` is not null';
$row = query_single_row($sql);
$count = reset($row);
-Stephen