Make a AJAX request containing the two coordinates of your cities that the API found.
In the PHP you can calculate the distance between two points without having to use the Javascript map api.
If you can have the coordinates without using the API you could calculate directly in PHP...
Javascript:
$.get( php_script , function( data ) {
alert( "The distance is "+data+" km" );
});
PHP:
unset($params);
$params["point1"]["lat"];
$params["point1"]["lng"];
$params["point2"]["lat"];
$params["point2"]["lng"];
echo orthodromy($params);
function orthodromy($params) {
unset($lat1, $lng1, $lat2, $lng2);
$lat1 = $params["point1"]["lat"];
$lng1 = $params["point1"]["lng"];
$lat2 = $params["point2"]["lat"];
$lng2 = $params["point2"]["lng"];
if (!is_numeric($lat1) || !is_numeric($lng1) || !is_numeric($lat2)
|| !is_numeric($lng2)) return false;
unset($dist);
$dist = acos(
sin( deg2rad($lat1) ) *
sin( deg2rad($lat2) ) +
cos( deg2rad($lat1) ) *
cos( deg2rad($lat2) ) *
cos( deg2rad($lng1-$lng2) )
) * 6371;
if (!is_numeric($dist)) return false; else return $dist;
}