| ユーザフォーラムで議論/質問 | マニュアル検索 | ハイライト | ハイライトオフ | ポータル | php spot |
Getting startedGetting started – getting started with the Services_GeoNames package
Instanciating the Services_GeoNames classTo instanciate the main class just do:
<?php
And if you have a commercial account: <?php require_once 'Services/GeoNames.php'; $geo = new Services_GeoNames('your_username', 'your_authtoken'); ?>
Using Services_GeoNames methodsTo call a webservice method, just instanciate the class as described above and call the desired method with an array of parameters, for example:
<?php
Every method take an array as single parameter, for example in the GeoNames API documentation when you see something like: Webservice Type : REST Url : ws.geonames.org/citiesJSON? Parameters : north,south,east,west : coordinates of bounding box callback : name of javascript function (optional parameter) lang : language of placenames and wikipedia urls (default = en) maxRows : maximal number of rows returned (default = 10) That means that you can call the cities() method as follows:
<?php
Note that for convenience, some methods can take a geonameId (integer) instead of the array as unique parameter, for example, the following two calls are equivalent:
<?php
Available methods
Handling exceptionsServices_GeoNames always raise either a Services_GeoNames_Exception or a Services_GeoNames_HTTPException instance, if you don't care of fine grained exceptions, you can just catch the Services_GeoNames_Exception, as it's the parent class of the Services_GeoNames_HTTPException. Here's an example of fine grained exception handling:
<?php
Changing the default service url and adding failover serversIf for some reason you need to change the web service url, you can do the following:
<?php
If you need high availability or if you are using the commercial version of the web services, Services_GeoNames allows you to specify an array of failover servers, you would just do:
<?php
Customizing the http requestIf you need a custom request, for example if you are behind a proxy, you can modify the Services_GeoNames request instance, for example:
<?php
For more infos please read the HTTP_Request2 documentation. |
各種マニュアル:
PHPマニュアル |
PEARマニュアル |
Smarty(英語)マニュアル |
PHP-GTKマニュアル |
「Getting started」をGoogle検索
|