Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Simple, standalone script that does quick latitude/longitude to city translation for US-based locations
branch: master

Renaming file to look better on github

Change-Id: Ieeb565f2a403ac3d80e3bd4c9717428331a9e245
latest commit 89fe651a4b
Eric Caron authored



Author: Eric Caron
Version: 1.0
Git: git clone

Geo2City is a PHP function that takes in one-or-more geo-location (in decimal latitude and longitude format) and returns the nearest city(s) in either an array, JSON or XML.

Geo2City evolved from needing some starting points for understanding latitude/longitude analysis and translating to nearest city/state. It is based to work in the US, but that's only because it pulls from zipcodes.csv (which is pulled from the public-domain works available at Is used caching, either memcache or APC, because loading & analyzing the CSV file each time is too expensive. In a typical production environment, the data should be stored in a database (like MySQL) and the caching-layer just introduces a new level of performance.

The first load will be slow, as its priming the cache. All subsequent loads will be very fast.

Bugs & Rationale

It has not been widely tested, is probably not suitable for production-use, and is mostly oriented towards small, started projects and people getting started in geo-coordination work. Yahoo's PlaceFinder API is a much better starting point:

Something went wrong with that request. Please try again.