通过Maxmind GeoLite2 Free获取用户城市的本地化名称 [英] Get a localized name of the users city via Maxmind GeoLite2 Free

查看:808
本文介绍了通过Maxmind GeoLite2 Free获取用户城市的本地化名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示用户所在城市的德语名称. Maxmind Geoip的免费版本可以吗? 我没有找到打开GeoLite2-City.mmdb或GeoLiteCity.dat来查看列出哪些城市来构建自己的翻译服务的方法.我如何打开它们?

i want to show the german name of the users city. Is it possible with the free Version of Maxmind Geoip? I did not find a way to open the GeoLite2-City.mmdb or GeoLiteCity.dat, to see which cities are listed, for building my own translation service. How can i open them?

推荐答案

GeoIP旧版数据库不包含本地化名称,但GeoIP2(或GeoLite2)数据库包含本地化名称.您可以按以下方式访问本地化名称:

The GeoIP Legacy database does not include localized names, but the GeoIP2 (or GeoLite2) database does. You may access the localized name as follows:

<?php
require_once 'vendor/autoload.php';
use GeoIp2\Database\Reader;

$reader = new Reader('/usr/local/share/GeoIP/GeoLite2-City.mmdb');

$record = $reader->city('128.101.101.101');

print($record->country->names['de'] . "\n");

或者,如果您希望读者默认使用德语,并在不可用时退回到英语,则可以在构造函数中设置语言:

Alternatively, if you would like the reader to default to German and fall back to English when it isn't available, you can set the language in the constructor:

<?php
require_once 'vendor/autoload.php';
use GeoIp2\Database\Reader;

$reader = new Reader('/usr/local/share/GeoIP/GeoLite2-City.mmdb', array('de', 'en'));

$record = $reader->city('128.101.101.101');

print($record->country->name . "\n");

这篇关于通过Maxmind GeoLite2 Free获取用户城市的本地化名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆