这里是我的功能:创建函数返回2个变量?
<?php
function latLng($str){
$address = $str;
// Initialize delay in geocode speed
$delay = 0;
$base_url = "http://maps.google.com/maps/geo?output=xml&key=" . $key;
// Iterate through the rows, geocoding each address
$geocode_pending = true;
$request_url = $base_url . "&q=" . urlencode($address);
$xml = simplexml_load_file($request_url) or die("url not loading");
$status = $xml->Response->Status->code;
if (strcmp($status, "200") == 0) {
// Successful geocode
$geocode_pending = false;
$coordinates = $xml->Response->Placemark->Point->coordinates;
$coordinatesSplit = split(",", $coordinates);
// Format: Longitude, Latitude, Altitude
$lat = $coordinatesSplit[1];
$lng = $coordinatesSplit[0];
} else if (strcmp($status, "620") == 0) {
// sent geocodes too fast
$delay += 100000;
} else {
// failure to geocode
$geocode_pending = false;
echo "Address " . $address . " failed to geocoded. ";
echo "Received status " . $status . "\n";
usleep($delay);
}
echo $lat . "<br />";
echo $lng;
}
echo latLng("Praha City Center, Klimentska 46, Prague, Czech Republic, 11002");
?>
它回声页上的纬度和经度完美,但我想他们回来作为变量,所以基本上我在功能包的地址,然后$lat
和$lng
变量返回到页面供我使用。
我该如何去做这件事?
谢谢
” ......找不到之间的距离经纬度/长等...' - 让你听起来很简单! – tomfumb
大声笑,我的意思是当然坐标对之间的距离:) – Zak