geolokace podle ip

Pro marketingové účely se mnohdy hodí lokalizovat uživatele, tedy alespoň přibližně. Využít můžete například službu GEO Plugin. Zjistíte jen velmi orientační polohu a další údaje, které se však většinou k ničemu nehodí. Lokalizace se provádí pomocí ip adresy uživatele.

Zašlete-li na web dotaz v následujícím tvaru

http://www.geoplugin.net/php.gp?ip=xx.xx.xx.xx

kde xx.xx.xx.xx. je ip adresa uživatele, obdržíte serializovaná data:

a:24:{s:17:“geoplugin_request“;s:13:“37.188.186.74″;s:16:“geoplugin_status“;i:200;s:15:“geoplugin_delay“;
s:3:“2ms“;s:16:“geoplugin_credit“;s:145:““;s:14:“geoplugin_city“;s:6:“Prague“;
s:16:“geoplugin_region“;s:18:“Hlavni mesto Praha“;s:20:“geoplugin_regionCode“;s:2:“10″;
s:20:“geoplugin_regionName“;s:18:“Hlavni mesto Praha“;s:18:“geoplugin_areaCode“;s:0:““;
s:17:“geoplugin_dmaCode“;s:0:““;s:21:“geoplugin_countryCode“;
s:2:“CZ“;s:21:“geoplugin_countryName“;s:7:“Czechia“;s:14:“geoplugin_inEU“;i:1;s:19:“geoplugin_euVATrate“;
i:21;s:23:“geoplugin_continentCode“;s:2:“EU“;s:23:“geoplugin_continentName“;s:6:“Europe“;s:18:“geoplugin_latitude“;
s:7:“50.0766″;s:19:“geoplugin_longitude“;s:7:“14.5148″;s:32:“geoplugin_locationAccuracyRadius“;
s:3:“100″;s:18:“geoplugin_timezone“;s:13:“Europe/Prague“;s:22:“geoplugin_currencyCode“;s:3:“CZK“;
s:24:“geoplugin_currencySymbol“;s:11:“Kč“;s:29:“geoplugin_currencySymbol_UTF8″;
s:3:“Kč“;s:27:“geoplugin_currencyConverter“;s:7:“22.2091″;}

která můžete unserialize na pole.

Obdržíte např.

Následně tedy stačí vzít například

a víte, kde (přibližně) se uživatel nachází.