Coding standards
Security in ResourceSpace
Developer reference
Database
User api session functions
Geolocation functions

fetch_country_coords()

Description

Resolve a country name, including multilingual English values, to coordinates.

Parameters

ColumnTypeDefaultDescription
$country_name string Uppercase country metadata.
$codes array Country name/code lookup entries.
$coords array Country code/coordinate lookup entries.

Return

array Latitude and longitude, or an empty array if unresolved.

Location

include/geolocation_functions.php lines 79 to 110

Definition

 
function fetch_country_coords($country_name, $codes, $coords)
{
    
# Resolve the country code for the given country name
    
$latlong = array();
    
$found = false;
    
reset($codes);
    foreach (
$codes as $code) {
        
$s = array_map('trim', explode(",", $code));
        if (
            
count($s) == 2
            
&& ((strtoupper($s[0]) == $country_name) || (strpos($country_name, "~EN:" . strtoupper($s[0])) !== false))
        ) {
            
$found = true;
            
$code = $s[1];
            break;
        }
    }
    if (
$found) {
        
# Resolve the coordinates for the country code
        
reset($coords);
        foreach (
$coords as $coord) {
            
# Each coord is country code, latitude, longitude
            
$s = array_map('trim', explode(",", $coord));
            if (
$s[0] == trim($code)) {
                
$latlong[0] = $s[1];
                
$latlong[1] = $s[2];
                break;
            }
        }
    }
    return 
$latlong;
}

This article was last updated 11th November 2026 19:05 Europe/London time based on the source file dated 11th November 2026 14:55 Europe/London time.