i need to develop a php script who ask for a city name and return a simple echo with the geographical coordinates of the city.
Input data: Cityname OR Cityname, Country
I know there is a free database called GeoNames were you can download a database who contains this information, but i really dont know how to export this database to my MySQL server, there 3 files who can be the think i need but i dont know what i need to pick:
cities1000.zip 11-Jul-2010 01:13 3.4M
cities15000.zip 11-Jul-2010 01:13 1.1M
cities5000.zip 11-Jul-2010 01:13 1.8M
So, its a good idea to use this data base?, there is an online API to do this?, how can i import the data from citiesXXXX to MySQL?, any suggestion for the php script?… Thanks!
I use Google Maps to get any information about a location: http://code.google.com/apis/maps/index.html
It can return the data in XML or JSON so you can easily parse and save the data.
Here is an example link for Washington DC: http://maps.google.com/maps/geo?output=xml&oe=utf8&sensor=false&hl=en&q=washington%20dc
It will return this XML data:
You can then use a function like SimpleXML or DOMDocument to parse the data. If you just want to echo the coordinates as supported in the tag simple use this code:
If you want the single coordinates use the data in the tag e.g.:
I hope that is what you are searching for.