1

Google지도가 올바르게 작동하도록 PHP 클라이언트를 가져오고 있습니다.Google지도 엔진 API Hello World MapItem을 찾지 못하는 PHP의 예

GitHub:https://github.com/google/google-api-php-client에서 GoogleAPI PHP 클라이언트의 로컬 사본을 다운로드했습니다.

IIS8에서 PHP v5.4를 실행 중입니다. GoogleAPI는 PHP 포함 폴더 GoogleAPI 아래에 설치되었습니다.

PHP가 다른 모든 스크립트에서 올바르게 작동합니다.

Maps-Engine Documentation에서 예제를 사용하려고합니다.

<?php 
 
ini_set('display_errors','on'); 
 

 
require('GoogleAPI/autoload.php'); 
 

 
//require_once 'GoogleAPI/src/Google/Client.php'; 
 
//require_once 'Google/Service/MapsEngine.php'; 
 

 
$apiKey = "API Key"; 
 

 
$client = new Google_Client(); 
 
$client->setApplicationName("Google-PhpMapsEngineSample/1.0"); 
 
$client->setDeveloperKey($apiKey); 
 

 
$service = new Google_Service_MapsEngine($client); 
 

 
$optParams = array('maxResults' => 500, 'version' => 'published'); 
 
$results = $service->tables_features->listTablesFeatures("12421761926155747447-06672618218968397709", $optParams); 
 

 
print_r($results); 
 

 
?>
코드 예제의 유일한 변화는 구글 자동 로더를로드하고 require_once를 지시문을 주석 API 키이었다.

내가받을 출력은 다음과 같습니다

Fatal error: Class 'Google_Service_MapsEngine_MapItem' not found in C:\Program Files (x86)\PHP\v5.4\includes\GoogleAPI\src\Google\Service\MapsEngine.php on line 4702 

MapsEngine : (4702)는 Google_Service_MapsEngine_MapItem 클래스를 확장합니다. Google_Service_MapsEngine_MapItem 클래스는 Model.php 파일에 정의 된 Google_Model 클래스를 확장합니다.

+0

실행시 require_once ('MapsEngine.php') 행을 주석 처리 하시겠습니까? – jpatokal

+0

예. AUTOLOADER가로드 중입니다. 필자는 오토로더가 호출 될 때 클래스 이름을 에코하여이를 확인했습니다. – Chann

답변

2

안녕하세요. 동일한 문제가있었습니다.

google-api-php-client/src/Google/Service/MapsEngine.php 파일에 버그가 있습니다. Google_Service_MapsEngine_MapItem을 소비하는 클래스 Google_Service_MapsEngine_MapFolder는 Google_Service_MapsEngine_MapItem 클래스가 선언되기 전에 선언됩니다.

MapsEngine.php 파일에서 2 개의 클래스 순서를 바꾸고 문제를 해결했습니다. 이것은 클래스의 올바른 순서를 보여줍니다.

class Google_Service_MapsEngine_MapItem extends Google_Model 
{ 
    protected $internal_gapi_mappings = array(
); 
    public $type; 


    public function setType($type) 
    { 
    $this->type = $type; 
    } 
    public function getType() 
    { 
    return $this->type; 
    } 
} 

class Google_Service_MapsEngine_MapFolder extends Google_Service_MapsEngine_MapItem 
{ 
    protected $collection_key = 'defaultViewport'; 
    protected $internal_gapi_mappings = array(
); 
    protected $contentsType = 'Google_Service_MapsEngine_MapItem'; 
    protected $contentsDataType = 'array'; 
    public $defaultViewport; 
    public $expandable; 
    public $key; 
    public $name; 
    public $visibility; 
    protected function gapiInit() 
    { 
    $this->type = 'folder'; 
    } 

    public function setContents($contents) 
    { 
    $this->contents = $contents; 
    } 
    public function getContents() 
    { 
    return $this->contents; 
    } 
    public function setDefaultViewport($defaultViewport) 
    { 
    $this->defaultViewport = $defaultViewport; 
    } 
    public function getDefaultViewport() 
    { 
    return $this->defaultViewport; 
    } 
    public function setExpandable($expandable) 
    { 
    $this->expandable = $expandable; 
    } 
    public function getExpandable() 
    { 
    return $this->expandable; 
    } 
    public function setKey($key) 
    { 
    $this->key = $key; 
    } 
    public function getKey() 
    { 
    return $this->key; 
    } 
    public function setName($name) 
    { 
    $this->name = $name; 
    } 
    public function getName() 
    { 
    return $this->name; 
    } 
    public function setVisibility($visibility) 
    { 
    $this->visibility = $visibility; 
    } 
    public function getVisibility() 
    { 
    return $this->visibility; 
    } 
}