📜  php 知道城市是否存在 gmap api - PHP 代码示例

📅  最后修改于: 2022-03-11 14:54:41.957000             🧑  作者: Mango

代码示例1
public static function  latlong($location) {

        if ($location!='') {
            try {
                $json = file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?address='.urlencode($location));
                $parsedjson = json_decode($json, true);

                if (key_exists(0,$parsedjson['results'])) {
                    $lat_long_array = $parsedjson['results'][0]['geometry']['location'];
                    return $lat_long_array;
                } else {
                    return false;
                }
            } catch (Exception $e) {
                //echo 'Caught exception: ',  $e->getMessage(), "\n";
                return false;
            }
        }


    }