代码之家  ›  专栏  ›  技术社区  ›  Jason

从地理编码中获取错误的经纬度

  •  0
  • Jason  · 技术社区  · 14 年前

    //Set up our variables
    $longitude = "";
    $latitude = "";
    
    
    //Three parts to the querystring: q is address, output is the format (
    $key=$er_mapapi; 
    $address=str_replace(' ', '%20', $_REQUEST['street_num'] . ' ' . $_REQUEST['address2'] . ', ' . $loccity . ', ' . $ststate . ', ' . $_REQUEST['postcode'] . ', ' . $cncount); 
    $url = "http://maps.google.com/maps/geo?q=".$address."&output=json&key=".$key;
    
    $ch = curl_init();
    
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER,0);
    curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    
    $data = curl_exec($ch);
    curl_close($ch);
    
    $geo_json = json_decode($data, true);
    
    print_r($geo_json);
    
    if ($geo_json['Status']['code'] == '200') {
    
    
    $latitude = $geo_json['Placemark'][0]['Point']['coordinates'][0];
    $longitude = $geo_json['Placemark'][0]['Point']['coordinates'][1];
    
    
    echo "Latutide: $latitude \n";
    echo "Longitude: $longitude \n";
    
    if ($latitude != '') $row->declat = $latitude; if ($longitude != '') $row->declong = $longitude; 
    
    
    } else {
    echo "Error in geocoding! Http error ".substr($data,0,3);
    }
    
    1 回复  |  直到 11 年前
        1
  •  3
  •   Kenan Banks    14 年前

    可能还有其他错误,但一开始看起来 KML returns point coordinates in (long, lat) order ,你的预期正好相反。