如何使用PHP使用GeoNames Web服务 [英] How to use GeoNames Web Services using PHP
问题描述
我已阅读此帖子,它看起来很有希望。然而,答案没有详细说明实现。
I have read this post and it looks very promising. However, the answer does not go in detail with regards the implementation.
基本上,如果考虑经纬度,我该如何使用 GeoNames Web服务获取国家。我希望返回的结果存储在一个变量中,以便我可以随时继续使用它。
Basically, given the latitude and longitude, how can I use the GeoNames Web Service to get the country. I would like the returned result to be stored in a variable so that I can then continue working with it as I wish.
预先致谢
推荐答案
你必须使用JavaScript吗? Geonames似乎没有提供JavaScript api来完成您的确切查询(请参阅: http: //www.geonames.org/export/JSON-webservices.html )。通过javascript远程获取文件并不是一件愉快的事情。
Do you have to use javascript for that? Geonames doesn't seem to offer a javascript api for doing your exact query (see here: http://www.geonames.org/export/JSON-webservices.html). And remote file fetching via javascript is not a joy.
如果您可以使用php,那就好比
If you could use php for that, it would be as easy as
$country = file_get_contents("http://ws.geonames.org/countryCode?lat=49.03&lng=10.2");
这篇关于如何使用PHP使用GeoNames Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!