How can PHP developers efficiently convert latitude/longitude coordinates to x/y coordinates for mapping purposes?

To efficiently convert latitude/longitude coordinates to x/y coordinates for mapping purposes, PHP developers can use the Haversine formula to calculate the distance between two points on the Earth's surface. This formula takes into account the curvature of the Earth to provide accurate results for mapping applications.

function latLongToXY($lat, $long) {
    $earthRadius = 6371000; // Earth's radius in meters
    $x = $earthRadius * deg2rad($long);
    $y = $earthRadius * log(tan((M_PI/4) + (deg2rad($lat)/2)));
    
    return ['x' => $x, 'y' => $y];
}

// Example usage
$latitude = 37.7749;
$longitude = -122.4194;
$xyCoordinates = latLongToXY($latitude, $longitude);

echo "X Coordinate: " . $xyCoordinates['x'] . "\n";
echo "Y Coordinate: " . $xyCoordinates['y'];