1

我正在尝试让 Google Map 的 PHP 客户端正常工作。

我已经从 GitHub 下载了 GoogleAPI PHP 客户端的本地副本:https://github.com/google/google-api-php-client

我在 IIS8 上运行 PHP v5.4。GoogleAPI 安装在 GoogleAPI 下的 PHP Include 文件夹

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);

?>
对代码示例的唯一更改是 API 密钥、加载 Google Autoloader 并注释掉 require_once 指令。

我收到的输出是:

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 类。

4

1 回答 1

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;
  }
}
于 2015-01-20T17:23:39.630 回答