Why don't you map each CountryCodeXXCountryCode to the respective continent? Shouldn't be too hard since there are only about 200 countries and 5 or 7 continents.
EDIT: I have no knowledge of such prepared database in PHP, but here is a json_encode'd array for all the countries with the country code as key and continent name as value:
如果您可以通过编程方式确定用户所在的国家/地区,那么您就有足够的信息来在您拥有的静态列表中查找他们所在的大陆。您自己收集这些信息并将其放入数据库或 XML 文件中需要花费一个小时,而且很少会发生变化。您已经花费了近乎那么多的时间来尝试找出如何动态确定大陆。
There's only 200ish countries and only 6 continents, so I would question why you need a web service to determine that bit of info... unless you plan on getting a lot of users from countries so politically unstable they will change names or cease to exist before your app does. Just keep a static list.
Also, not all countries are on a continent. New Zealand for example, isn't part of Australia (according to Wikipedia at least).
If you can determine the user's country programmatically, you have enough information to look up their continent in a static list which you own. It would take you an hour to assemble that info yourself and put it in a database or XML file, and it will rarely change. You've already spent nearly that amount of time trying to find out how to determine the continent dynamically.
If it's the continent you're mainly after (I don't know if GeoLite stores that) you could always map the country codes from the GeoLite database to the country codes of the world database which MySql uses as a sample database. That has the continent for each country stored.
发布评论
评论(4)
为什么不将每个 CountryCodeXXCountryCode 映射到相应的大陆?应该不会太难,因为只有大约 200 个国家和 5 或 7 大洲。
编辑:我对 PHP 中准备好的数据库一无所知,但这里有一个 json_encode 所有国家的数组,以国家/地区代码为键,以大陆名称为值:
只需使用以下命令调用它:
Why don't you map each CountryCodeXXCountryCode to the respective continent? Shouldn't be too hard since there are only about 200 countries and 5 or 7 continents.
EDIT: I have no knowledge of such prepared database in PHP, but here is a json_encode'd array for all the countries with the country code as key and continent name as value:
Just call it with:
只有 200 个左右的国家和 6 大洲,所以我会质疑为什么你需要一个网络服务来确定这些信息......除非你计划从政治不稳定的国家获得大量用户,他们会更改名称或不复存在在您的应用程序之前。只需保留一个静态列表即可。
此外,并非所有国家都位于一个大陆上。例如,新西兰不属于澳大利亚(至少根据维基百科)。
如果您可以通过编程方式确定用户所在的国家/地区,那么您就有足够的信息来在您拥有的静态列表中查找他们所在的大陆。您自己收集这些信息并将其放入数据库或 XML 文件中需要花费一个小时,而且很少会发生变化。您已经花费了近乎那么多的时间来尝试找出如何动态确定大陆。
There's only 200ish countries and only 6 continents, so I would question why you need a web service to determine that bit of info... unless you plan on getting a lot of users from countries so politically unstable they will change names or cease to exist before your app does. Just keep a static list.
Also, not all countries are on a continent. New Zealand for example, isn't part of Australia (according to Wikipedia at least).
If you can determine the user's country programmatically, you have enough information to look up their continent in a static list which you own. It would take you an hour to assemble that info yourself and put it in a database or XML file, and it will rarely change. You've already spent nearly that amount of time trying to find out how to determine the continent dynamically.
查看 MaxMind GeoLite Country 和 MaxMind GeoLite City。
如果它是您主要寻找的大陆(我不知道 GeoLite 是否存储了该大陆),您始终可以将 GeoLite 数据库中的国家/地区代码映射到 world 数据库,MySql 使用它作为示例数据库。 其中存储了每个国家/地区的大陆。
Have a look MaxMind GeoLite Country and MaxMind GeoLite City.
If it's the continent you're mainly after (I don't know if GeoLite stores that) you could always map the country codes from the GeoLite database to the country codes of the world database which MySql uses as a sample database. That has the continent for each country stored.
尝试 http://www.geobytes.com/IpLocator.htm?GetLocation
我使用他们一直在线接口,从未尝试过API。
Try http://www.geobytes.com/IpLocator.htm?GetLocation
I use their online interface all the time, never tried the API.