Coding standards
Security in ResourceSpace
Developer reference
Database
Action functions
Admin functions
Ajax functions
Annotation functions
API functions
Collections functions
Comment functions
Config functions
CSV export functions
Dash functions
Debug functions
Encryption functions
Facial recognition functions
File functions
General functions
Language functions
Log functions
Login functions
Message functions
Migration functions
Node functions
PDF functions
Plugin functions
Render functions
Reporting functions
Request functions
Research functions
Slideshow functions
Theme permission functions
User functions
Video functions
Database functions
Metadata functions
Resource functions
Search functions
Map functions
Job functions
Tab functions
Test functions

update_geolocation_fields()

Description

Update the geo location fields (if set) for the given resource(s).
User permissions are not checked as this should be used in cases where the user has already edited the location.

Otherwise an array with two integer values being the latitude and longitude.

Parameters

ColumnTypeDefaultDescription
$resources integer|array The resource ref(s) as a single integer or an array of integers.
$location: string|array
$location string|array The new location to use, a blank string to clear the location from the resource(s).

Return

void

Location

include/metadata_functions.php lines 516 to 553

Definition

 
function update_geolocation_fields(int|array $resourcesstring|array $location): void
{
    if (
        
$location !== "" 
        
&& (!is_array($location) || count($location) !== 2
            
|| !is_numeric($location[0]) || !is_numeric($location[1])
            || (float)
$location[0] < -90 || (float)$location[0] > 90
            
|| (float)$location[1] < -180 || (float)$location[1] > 180
            
)
        ) {
        throw new 
InvalidArgumentException('Invalid location format');
    }

    
$fields ps_query("SELECT ref, geomapping FROM resource_type_field WHERE geomapping != 0", []);
    if (empty(
$fields)) {
        return;
    }

    if (!
is_array($resources)) {
        
$resources = [$resources];
    } else {
        
$resources array_filter($resources'is_positive_int_loose');
    }

    foreach(
$resources as $ref) {
        foreach(
$fields as $field) {
            if (
$location == "") {
                
update_field($ref$field["ref"], "");
            } elseif (
$field["geomapping"] == FIELD_GEO_LOCATION::both->value) {
                
update_field($ref$field["ref"], $location[0] . ", " $location[1]);
            } elseif (
$field["geomapping"] == FIELD_GEO_LOCATION::latitude->value) {
                
update_field($ref$field["ref"], $location[0]);
            } elseif (
$field["geomapping"] == FIELD_GEO_LOCATION::longitude->value) {
                
update_field($ref$field["ref"], $location[1]);
            }
        }
    }
}

This article was last updated 19th May 2026 13:05 Europe/London time based on the source file dated 19th May 2026 12:00 Europe/London time.