// $json = json_decode(file_get_contents($url), true); // return $json[0]["lat"].",".$json[0]["lon"]; // echo rawurlencode('viale oriani alfredo 33'); $str = "viale 12"; // $splitted = split(" ",$str); // $street = ""; // for ($i=0; $i < count($splitted) -1 ; $i++) { // if ( $i == count($splitted) -2) { // $street .= $splitted[$i+1]." ".$splitted[$i]; // break; // }else // $street .= $splitted[$i]." "; // } // $street = trim($street); // echo "$street"; $x = getUrlFromAddrAndCity2("via gusto righi", 3, 'bo'); echo "{$x}"; // $pstr = ""; // $pnum = ""; // foreach ($splitted as $item) { // if (is_numeric($item)) { // $pnum = $item; // }else{ // $pstr .= $item." "; // } // } //echo trim($pnum." ".$pstr); function getUrlFromAddrAndCity2($street, $num, $city) { $splitted = split(" ", $street); echo "aa " . count($splitted);
function geocodeByCity($street, $num, $city) { $url = getUrlFromAddrAndCity($street, $num, $city); $json = json_decode(file_get_contents($url), true); if ($json[0]["lat"] == null) { $url = getUrlFromAddrAndCity2($street, $num, $city); $json = json_decode(file_get_contents($url), true); } $_SESSION['addrurl'] = $url; return $json[0]["lat"] . "," . $json[0]["lon"]; }