2017 © Pedro Peláez
 

yii2-extension yii2-geolocation

Simple Yii2 component to find geo client information.

image

indicalabs/yii2-geolocation

Simple Yii2 component to find geo client information.

  • Tuesday, February 20, 2018
  • by indicalabs
  • Repository
  • 1 Watchers
  • 0 Stars
  • 131 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 6 % Grown

The README.md

yii2-geolocation

This is modified extension of https://github.com/rodzadra/yii2-geolocation, (*1)

Thanks to rodzadra., (*2)

Simple Yii2 component to find geo client information., (*3)

Yii2, (*4)

Installation

Installation

The preferred way to install this extension is through composer., (*5)

Either run, (*6)

composer require --prefer-dist indicalabs/yii2-geolocation "*"

or add, (*7)

"indicalabs/yii2-geolocation": "*"

to the require section of your composer.json file., (*8)

Configuration

1) In your config/main.php, (*9)


'components'=>[ 'geolocation' => [ 'class' => 'indicalabs\geolocation\Geolocation', 'config' => [ 'provider' => '[PLUGIN_NAME]', 'return_formats' => '[SUPORTED_PLUGIN_FORMATS]', 'api_key' => '[YOUR_API_KEY], ], ], ],

Config params


provider - The name of plugin to use (see examples on @vendor/indicalabs/geolocation/plugins/); return_formats - The return formats supported by the plugin api_key - If necessary, you can pass your api key here.

Plugins

Plugins are simple PHP files, that returns an array with three vars:, (*10)

  • plugin_url : URL of webservice, with three special tags:

a) {{accepted_formats}}, (*11)

b) {{ip}}, (*12)

c) {{api_key}}, (*13)

These tags will be replaced by their respective values., (*14)

  • accepted_formats : An array with the return acceptable formats (example ['csv', 'php', 'json', 'xml']), (*15)

  • default_accepted_format : String with the default return format. (example "php"), (*16)

Plugin file example

 'http://www.geoplugin.net/{{accepted_formats}}.gp?ip={{ip}}',
            'accepted_formats'          => ['json', 'php', 'xml'],
            'default_accepted_format'   => 'php',
    ];

```


### How to use

In your view:

```php

geolocation->getInfo());
?>

or, to find the geolocation infos from Google server, on your view., (*17)


geolocation->getInfo('173.194.118.22')); ?>

To change the plugin


geolocation->getPlugin('ippycox','XML'); print_r(yii::$app->geolocation->getInfo('173.194.118.22')); ?>

What you get?

Using the geoplugin provider:, (*18)

Array
(
    [geoplugin_request] => 173.194.118.22
    [geoplugin_status] => 200
    [geoplugin_credit] => Some of the returned data includes GeoLite data created by MaxMind, available from http://www.maxmind.com.
    [geoplugin_city] => Mountain View
    [geoplugin_region] => CA
    [geoplugin_areaCode] => 650
    [geoplugin_dmaCode] => 807
    [geoplugin_countryCode] => US
    [geoplugin_countryName] => United States
    [geoplugin_continentCode] => NA
    [geoplugin_latitude] => 37.419201
    [geoplugin_longitude] => -122.057404
    [geoplugin_regionCode] => CA
    [geoplugin_regionName] => California
    [geoplugin_currencyCode] => USD
    [geoplugin_currencySymbol] => $
    [geoplugin_currencySymbol_UTF8] => $
    [geoplugin_currencyConverter] => 1
)

For more information, please visit http://www.geoplugin.com/, (*19)

Using the freegeoip provider:, (*20)


{ "ip":"173.194.118.22", "country_code":"US", "country_name":"United States", "region_code":"CA", "region_name":"California", "city":"Mountain View", "zip_code":"94043", "time_zone":"America/Los_Angeles", "latitude":37.419, "longitude":-122.058, "metro_code":807 }

For more information, please visit https://freegeoip.net/, (*21)

For another plugins infos, please use the sources. :), (*22)

The Versions

20/02 2018

dev-master

9999999-dev

Simple Yii2 component to find geo client information.

  Sources   Download

GPL v.3 GPL-3.0-only

The Requires

 

by Venu Narukulla

extension yii2 geolocation