0

최근까지 Google 지오 코딩을 사용하여 데이터베이스에 저장 될 좌표를 제공했습니다. 그러나 최근에이 작업을 시도 할 때 오류 610이 발생하여 실패했습니다. 여전히 v2를 사용하고 있었고이 단계적으로 제거되고 있음을 이해했습니다. 그래서,이 웹 사이트에 와서이 스레드를 보았습니다 : Changing from Google maps api v2 to v3.Google 지오 코더 v2 및 v3

define("MAPS_HOST", "maps.googleapis.com"); 
$base_url = "http://" . MAPS_HOST . "/maps/api/geocode/xml?"; 

$request_url = $base_url . "address=" . urlencode($address) . "&sensor=false"; 

지오 코딩 v3의 주소를 변경하고 두 번째 반환에있는 경로를 변경,

이이 :이 스레드에서 (내가 근무 피드백을 이해) 다음에 맞춰 내 코드를 업데이트 설정 XML 파일 위도/경도

$coordinates = $xml->Response->Placemark->Point->coordinates; 
    $coordinatesSplit = split(",", $coordinates); 
    // Format: Longitude, Latitude, Altitude 

    $lat = $coordinatesSplit[1]; 

    $lng = $coordinatesSplit[0]; 

완전히

$lat = $xml->result->geometry->location->lat; 
    $lng = $xml->result->geometry->location->lng; 
,536,913로 대체 할 수

그러나 여전히 나를 위해 일하지 않습니다. 나는 그것을 실행하려고 할 때 더 이상 오류 610이 발생하지 않고 단지 "오류 코드를 지오 코딩하지 못했습니다".

죄송합니다. 나는 아직도이 제품에 대해 비교적 초보적이며, 실제로 배우면서 배우는데 도움을 주셔서 감사합니다. 그것은 내가 놓친 가장 간단한 일이 될 수 있습니다. 현재 내 코드는 다음과 같습니다.

<?php 
    require("phpsqlgeocode_dbinfo.php"); 

    define("MAPS_HOST", "maps.googleapis.com"); 
    define("KEY", *my key*); 

    // Opens a connection to a MySQL server 
    $connection = mysql_connect('*name*', $username, $password); 
    if (!$connection) { 
     die("Not connected : " . mysql_error()); 
    } 

    // Set the active MySQL database 
    $db_selected = mysql_select_db($database, $connection); 
    if (!$db_selected) { 
     die("Can\'t use db : " . mysql_error()); 
    } 

    // Select all the rows in the markers table 
    $query = "SELECT * FROM markers WHERE 1"; 
    $result = mysql_query($query); 
    if (!$result) { 
     die("Invalid query: " . mysql_error()); 
    } 

    // Initialize delay in geocode speed 
    $delay = 0; 
    $base_url = "http://" . MAPS_HOST . "/maps/api/geocode/xml?"; 

    // Iterate through the rows, geocoding each address 
    while ($row = @mysql_fetch_assoc($result)) { 
     $geocode_pending = true; 

     while ($geocode_pending) { 
     $address = $row["address"]; 
     $id = $row["id"]; 
     $request_url = $base_url . "address=" . urlencode($address) . "&sensor=false"; 
$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; 
    $lat = $xml->result->geometry->location->lat; 
    $lng = $xml->result->geometry->location->lng; 

    $query = sprintf("UPDATE markers " . 
     " SET lat = '%s', lng = '%s' " . 
     " WHERE id = '%s' LIMIT 1;", 
     mysql_real_escape_string($lat), 
     mysql_real_escape_string($lng), 
     mysql_real_escape_string($id)); 
    $update_result = mysql_query($query); 
    if (!$update_result) { 
    die("Invalid query: " . mysql_error()); 
    } 
} 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); 
     } 
    } 
    ?> 

감사합니다.

+0

가능한 중복 (http://stackoverflow.com/questions/16762433/google-geocoding-using-v3-not-showing-error) –

답변

0

이것은 내가 한 행동입니다. 나는 똑같은 문제를 겪고 있었고 이제 모든 것이 완벽하게 작동합니다.

<?php 

     $sql = "SELECT * FROM locations WHERE lat IS NULL AND lng IS NULL"; 
      $res = mysql_query($sql); 
      while($row = mysql_fetch_assoc($res)) { 
       $address = $row['address_1'] . ", " . $row['city'] . " " . $row['state'] . " " . $row['zip']; 
       $latlng = geocode($address); 
       echo $address . "<br />"; 
       if($latlng[0] && $latlng[1]) { 
        print_r($latlng); 
        echo "<br />"; 
        $update = "UPDATE locations SET lat = '" . $latlng[0] . "', lng = '" . $latlng[1] . "' WHERE id = " . $row['id'] . " LIMIT 1"; 
        $update_res = mysql_query($update); 
        echo $update . "<br />"; 
       } else { 
        echo $latlng[2] . "<br />"; 
       } 
       echo "<br />"; 
      } 

function geocode($address) { 
    if(empty($address)) { 
     return array("", "", ""); 
    } 

    $base_url = "http://maps.googleapis.com/maps/api/geocode/xml"; 
    $request_url = $base_url . "?address=" . urlencode($address) . "&sensor=false" ; 
    $xml = simplexml_load_file($request_url); 
    $status = $xml->status; 
    if (strcmp($status, "OK") == 0) { 

     $lat = $xml->result->geometry->location->lat; 
     $lng = $xml->result->geometry->location->lng; 
     return array($lat, $lng, $request_url); 
    } else { 
     return array("", "", $request_url); 
    } 
} 

?> 
[오류가 표시되지 v3의 사용 구글 지오 코딩]의