Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Geodata


WordPress does not include any geographic functionality or functions to deal with Geodata itself (something that might be called a Geodata API). But there is a standard for how to store geodata, so that plugins can interoperate.

Where to store Geodata ?

Geodata for an object should be stored in the metadata for that object.

  • Geodata for posts, pages and other post-types should be stored in postmeta.
  • Geodata for users should be stored in usermeta.
  • Geodata for comments should be stored in commentmeta.
  • Geodata for terms should be stored in termmeta.

Geodata Format

Meta keys and their meta values are listed below.

geo_latitude REQUIRED
(float) decimal degrees -90 to 90 (negative values are in the southern hemisphere).
geo_longitude REQUIRED
(float) decimal degrees -180 to 180 (negative values are in the western hemisphere).
geo_public OPTIONAL
(int) is the geodata public (1) or private (0)? If value is missing or not set to 0, assume public.
geo_address OPTIONAL
(string) freeform textual description of coordinates.
"221B Baker St, Westminster, London NW1 6XE, UK",
"Pasadena, CA", "Soho, NYC", "Idaho", etc.
Accuracy level and language is arbitrary.

The W3C Geolocation API([1]), introduced in 2014, offers the additional geolocation properties of altitude, accuracy, altitudeAccuracy, speed, and heading, which if adopted by any plugin to ensure compatibility with this, should be stored with the geo_ prefix.