Searching for business addresses using the Google Maps API

You would like to search for the address of a well-known business in your area.

Getting ready

You can use the Python geocoding library pygeocoder to search for a local business. You need to install this library from PyPI with pip or easy_install, by entering $ pip install pygeocoder or $ easy_install pygeocoder.

How to do it...

Let us find the address of Argos Ltd., a well-known UK retailer using a few lines of Python code.

Listing 6.1 gives a simple geocoding example to search for a business address, as follows:

#!/usr/bin/env python

# Python Network Programming Cookbook -- Chapter - 6
# This program is optimized for Python 2.7.
# It may run on any other version with/without modifications.

from pygeocoder import Geocoder

def search_business(business_name):

  results = Geocoder.geocode(business_name)
  
  for result in results:
    print result

if __name__ == '__main__':
  business_name =  "Argos Ltd, London" 
  print "Searching %s" %business_name
  search_business(business_name)

This recipe will print the address of Argos Ltd., as shown. The output may vary slightly based on the output from your installed geocoding library:

$ python 6_1_search_business_addr.py
Searching Argos Ltd, London 

Argos Ltd, 110-114 King Street, London, Greater London W6 0QP, UK

How it works...

This recipe relies on the Python third-party geocoder library.

This recipe defines a simple function search_business() that takes the business name as an input and passes that to the geocode() function. The geocode() function can return zero or more search results depending on your search term.

In this recipe, the geocode() function has got the business name Argos Ltd., London, as the search query. In return, it gives the address of Argos Ltd., which is 110-114 King Street, London, Greater London W6 0QP, UK.

See also

The pygeocoder library is powerful and has many interesting and useful features for geocoding. You may find more details on the developer's website at https://bitbucket.org/xster/pygeocoder/wiki/Home.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.220.124.177