Jeffrey McManus

The New Thing

Jeffrey McManus header image 3

PlacemakerPHP Wrapper Class for Yahoo! Placemaker API

Yahoo recently released the Placemaker API, a handy service that translates blobs of text into location references (longitude/latitude, etc.) suitable for plotting on a map.

Unfortunately, it looks like Yahoo couldn’t be bothered to release any language-specific wrappers or code examples for this API, which makes using it a drag if you’ve never used a Yahoo API before. So here’s a little wrapper class that enables you to do a lookup against this API with just a few lines of PHP. The download also includes a test file that shows you how to use the class from your PHP script.

The wrapper class handles the naive case of converting a blob of text into a single location reference comprised of name, latitude, and longitude. I realize that there are more cases that the API deals with that this wrapper doesn’t handle — contributions are welcome if you’d care to tackle those yourself.

This probably requires PHP5 and it definitely requires cURL, which I guess you have automatically if you have PHP5.

I licensed this under GPL specifically to be difficult; if this doesn’t work for you for whatever reason contact us and let’s talk.

Update: Version 0.1.2 renames the class and PHP file so this can be used as a CodeIgniter library. Also changed the get() method so it returns an instance of itself, and added some tests to properly handle situations when the input text has no place data in it.

Download: PlacemakerPHP.zip version 0.1.2, 3. June 2009

4 Comments

4 Comments so far ↓

  • Ryan Kennedy

    Your class doesn’t handle multiple locations. Try changing the text in your test to “I would love to live in Madagascar or London someday.” You only get back the London location from your library, completely losing the location for “Madagascar”.

    Current score: 0
  • jeffrey

    Fixed in 0.1.1. Thanks for yr feedback!

    Current score: 0
  • Dominik

    I’m getting an error – “Class ‘PlacemakerLocation’ not found” – and well, there is no class PlacemakerLocation..

    Current score: 0
  • jeffrey

    Try downloading the latest version. In 0.1.2 I changed the name of the class; it’s not called PlacemakerLocation anymore, just Placemaker.

    Current score: 0

Leave a Comment