Getting Started - adampresley/placefinder-py GitHub Wiki

This page will cover a few of the most basic usage examples for placefinder-py.

A Simple Address Query

The most basic, and probably more powerful types of geocoding query offered by Yahoo! BOSS PlaceFinder services is the free-form format query. This type of query allows you to enter an address, partial or full, and PlaceFinder will attempt to find matching locations.

To do this with placefinder-py you start by importing the module, creating an instance of the class, then calling the geocodeFreeform() method. Here is an example that performs a geocode query for a Starbucks in New York, and how to get the latitude and longitude information for the first match.

from placefinder import PlaceFinder, InvalidSearchQueryException

KEY = "YOUR KEY"
SECRET = "YOUR SECRET"
APP_ID = "YOUR APP ID"

placefinder = PlaceFinder(KEY, SECRET, APP_ID)

try:
   response, content, results = placefinder.geocodeFreeform("80 Delancey Street, New York, NY 10002")
   print "Latitude: %s, Longitude: %s" % (results[0]["latitude"], results[0]["longitude"])

except InvalidSearchQueryException as e:
   print "Oops! The query you passed is invalid!"

A Multi-line Address Query

Given a situation where you have the address information split into multiple variables you can call geocodeMultiline() to geocode the address. This is handy, for example, when you have a form on a webpage with address, city, state, and ZIP code all as separate fields. These can be passed to this method to perform the geocode operation.

from placefinder import PlaceFinder, InvalidSearchQueryException

KEY = "YOUR KEY"
SECRET = "YOUR SECRET"
APP_ID = "YOUR APP ID"

placefinder = PlaceFinder(KEY, SECRET, APP_ID)

try:
   response, content, results = placefinder.geocodeMultiline("80 Delancey Street", "New York", "NY", "10002")
   print "Latitude: %s, Longitude: %s" % (results[0]["latitude"], results[0]["longitude"])

except InvalidSearchQueryException as e:
   print "Oops! The query you passed is invalid!"

Reverse Geocoding

Now let's assume that you have a latitude and longitude point and you would like to find out what address this maps to. This is called reverse geocoding, and the PlaceFinder API supports this. Using the method reverseGeocode() you pass in both latitude and longitude and you will receive a response of a possible address match.

from placefinder import PlaceFinder, InvalidSearchQueryException

KEY = "YOUR KEY"
SECRET = "YOUR SECRET"
APP_ID = "YOUR APP ID"

placefinder = PlaceFinder(KEY, SECRET, APP_ID)

try:
   response, content, results = placefinder.reverseGeocode(latitude = 29.941889, longitude = -90.129538)

   if len(results):
      print "Address:"
      print results[0]["line1"]
      print results[0]["line2"]

   else:
      print "No match found."

except InvalidSearchQueryException as e:
   print "Oops! The query you passed is invalid!"