This repository has been archived by the owner on Jun 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
71 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,91 @@ | ||
Google Maps Simple Geocode | ||
========================== | ||
# PHP Google Maps Geocode | ||
|
||
[![Build Status](https://travis-ci.org/dotzero/gmaps-geocode-php.svg?branch=master)](https://travis-ci.org/dotzero/gmaps-geocode-php) | ||
[![Latest Stable Version](https://poser.pugx.org/dotzero/gmaps-geocode/version)](https://packagist.org/packages/dotzero/gmaps-geocode) | ||
[![License](https://poser.pugx.org/dotzero/gmaps-geocode/license)](https://packagist.org/packages/dotzero/gmaps-geocode) | ||
|
||
A PHP5 library implements Geocoding and Reverse geocoding through The Google Maps Geocoding API. | ||
|
||
Geocoding is the process of converting addresses (like "1600 Amphitheatre Parkway, Mountain View, CA") into geographic coordinates (like latitude 37.423021 and longitude -122.083739). Reverse geocoding is the process of converting geographic coordinates into a human-readable address. | ||
|
||
## Usage | ||
|
||
To use the Google Maps Geocoding API, you need an API key. To acquire an API key follow [the instructions](https://developers.google.com/maps/documentation/geocoding/get-api-key). | ||
|
||
### Geocoding (Latitude/Longitude Lookup) | ||
|
||
```php | ||
try { | ||
$result = (new GMapsGeocode('YOUR_GOOGLE_API')) | ||
->setAddress('Helsinki') | ||
// ->setRegion('FI') | ||
->setComponents(array( | ||
'route' => 'Annegatan', | ||
'administrative_area' => 'Helsinki', | ||
'country' => 'Finland' | ||
)) | ||
->search(); | ||
|
||
print_r($result); | ||
} catch (GMapsException $e) { | ||
printf('Error (%d): %s', $e->getCode(), $e->getMessage()); | ||
} | ||
``` | ||
|
||
Класс для реализации геокодирования (преобразования адресов в географические координаты) | ||
с использованием сервиса геокодирования Google Maps Geocoding. | ||
Required method are `setAddress` or `setComponents` in a geocoding request and `setRegion` is optional. | ||
|
||
### Основные методы класса | ||
[Official documentation](https://developers.google.com/maps/documentation/geocoding/intro?hl=en#ComponentFiltering) contains more about Component Filtering. | ||
|
||
Обращаение к экземпляру класса | ||
### Reverse Geocoding (Address Lookup) | ||
|
||
GoogleMapsSimpleGeocode::getInstance(); | ||
```php | ||
try { | ||
$geo = (new GMapsGeocodeReverse('YOUR_GOOGLE_API')) | ||
->setLatLng('40.714224', '-73.961452') | ||
// ->setPlaceId('ChIJd8BlQ2BZwokRAFUEcm_qrcA') | ||
->search(); | ||
|
||
Основной метод для геокодирования адреса по установленным параметрам. | ||
При использовании параметра `$raw = true` вернет ответ сервиса без обработки. | ||
print_r($result); | ||
} catch (GMapsException $e) { | ||
printf('Error (%d): %s', $e->getCode(), $e->getMessage()); | ||
} | ||
``` | ||
|
||
search($raw = false) | ||
Required method are `setLatLng` or `setPlaceId` in a reverse geocoding request. | ||
|
||
В случае возникновения ошибки метод будет хранить текст ошибки. | ||
## Install | ||
|
||
errorMessage() | ||
### Via composer: | ||
|
||
### Методы для установки параметром геокодирования | ||
```bash | ||
$ composer require dotzero/gmaps-geocode | ||
``` | ||
|
||
Установка адреса, который нужно геокодировать | ||
### Without composer | ||
|
||
setAddress($address) | ||
Clone the project using: | ||
|
||
Установка Google Api Key | ||
```bash | ||
$ git clone https://github.com/dotzero/gmaps-geocode-php/ | ||
``` | ||
|
||
setApiKey($apikey) | ||
and include the source files with: | ||
|
||
Исходит ли запрос на геокодирование от устройства с датчиком местоположения | ||
```php | ||
require_once("gmaps-geocode-php/src/GMapsException.php"); | ||
require_once("gmaps-geocode-php/src/GMapsGeocodeBase.php"); | ||
require_once("gmaps-geocode-php/src/GMapsGeocode.php"); | ||
require_once("gmaps-geocode-php/src/GMapsGeocodeReverse.php"); | ||
``` | ||
|
||
setSensor($flag = false) | ||
## Test | ||
|
||
Установка формата ответа Службы геокодирования. Доступные форматы: `xml`, `csv`, `json`. | ||
По-умолчанию установлен `csv`. | ||
First install the dependencies, and after you can run: | ||
|
||
setOutput($format) | ||
```bash | ||
GOOGLE_API=YOUR_GOOGLE_API vendor/bin/phpunit | ||
``` | ||
|
||
Установка формата кодировки результатов | ||
## License | ||
|
||
setEncoding($charset = 'utf8') | ||
Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php |