skip to navigation
skip to content

Not Logged In

geocoder 0.3.63

Python (Google) Geocoder

Latest Version: 0.5.1

https://badge.fury.io/py/geocoder.png https://pypip.in/d/geocoder/badge.png

A simplistic Python Geocoder.

Geocoder is an Apache2 Licensed Geocoding library, written in Python.

>>> import geocoder
>>> g = geocoder.google('Moscone Center')
>>> g.latlng
(37.784173, -122.401557)
>>> g.city
'San Francisco'
...

Installation

To install Geocoder, simply:

$ pip install geocoder

Documentation

Basic Usage

>>> import geocoder
>>> g = geocoder.google('1600 Amphitheatre Pkwy, Mountain View, CA')
>>> g.latlng
(37.784173, -122.401557)
>>> g.postal
'94043'
>>> g.city
'Mountain View'
>>> g.country
'United States'
...

Getting JSON

>>> g = geocoder.google('1600 Amphitheatre Parkway, Mountain View, CA')
>>> g.json
{'address': '1600 Amphitheatre Parkway, Mountain View, CA 94043, USA',
'bbox': {'northeast': {'lat': 37.4233474802915, 'lng': -122.0826054197085},
'southwest': {'lat': 37.4206495197085, 'lng': -122.0853033802915}},
'city': 'Mountain View',
'country': 'United States',
'lat': 37.4219985,
'lng': -122.0839544,
'location': '1600 Amphitheatre Parkway, Mountain View, CA 94043, USA',
'ok': True,
'postal': '94043',
'provider': 'Google',
'quality': 'ROOFTOP',
'status': 'OK'}
...

Reverse Geocoding

## Input methods
>>> geocoder.reverse(lat, lng)
>>> geocoder.reverse(latlng)

## Results
>>> latlng = (48.85837, 2.2944813)
>>> g = geocoder.reverse(latlng)
<[OK] Geocoder Google [Eiffel Tower, Paris, France]>
...

Bounding Box (Extent)

>>> g = geocoder.osm('1600 Amphitheatre Pkwy, Mountain View, CA')
>>> g.bbox
{'northeast': {'lat': 37.4233474802915, 'lng': -122.0826054197085},
'southwest': {'lat': 37.4206495197085, 'lng': -122.0853033802915}}
>>> g.southwest
{'lat': 37.4206495197085, 'lng': -122.0853033802915}
>>> g.south
37.4206495197085
...

Geocoding IP Address

>>> ip = geocoder.ip('74.125.226.99')
>>> ip.latlng
(37.4192, -122.0574)
>>> ip.address
'Mountain View, California United States'

## Try using Reverse Geocoding with your results
>>> g = geocoder.reverse(ip.latlng)
>>> g.address
'Sevryns Road, Mountain View, CA 94043, USA'
...

Geocoding using a Loop

>>> for provider in ['google', 'osm', 'mapquest']:
>>>     g = geocoder.get(<location>, provider=provider)
...

Geocoder Attributes

  • address
  • location
  • city
  • country
  • postal
  • quality
  • status
  • ok (boolean)
  • x, lng, longitude (float)
  • y, lat, latitude (float)
  • latlng, xy (tuple)
  • bbox {southwest, northeast}
  • southwest {lat, lng}
  • northeast {lat, lng}
  • south, west, north, east (float)

Geocoding Providers

## Priority Geocoders
>>> geocoder.google(<location>)
>>> geocoder.osm(<location>)

## Secondary Geocoders
>>> geocoder.mapquest(<location>)
>>> geocoder.esri(<location>)
>>> geocoder.bing(<location>, key='XXXXX')
>>> geocoder.nokia(<location>, app_id='XXXXX', app_code='XXXXX')
>>> geocoder.tomtom(<location>, key='XXXXX')
...

Command Line

$ geocoder Ottawa
45.4215296, -75.69719309999999

More interaction with command line will soon follow.

Contribute

Please feel free to give any feedback on this module, it is still in it's early stages of production. If you have any questions about GIS & Python you can contact @DenisCarriere for any questions.

 
File Type Py Version Uploaded on Size
geocoder-0.3.63.tar.gz (md5) Source 2014-02-23 8KB
  • Downloads (All Versions):
  • 140 downloads in the last day
  • 576 downloads in the last week
  • 9946 downloads in the last month
  • Author: Denis Carriere
  • Home Page: https://github.com/DenisCarriere/geocoder
  • Download URL: https://github.com/DenisCarriere/geocoder/tarball/master
  • License:
    Copyright 2014 Denis Carriere
    
       Licensed under the Apache License, Version 2.0 (the "License");
       you may not use this file except in compliance with the License.
       You may obtain a copy of the License at
    
           http://www.apache.org/licenses/LICENSE-2.0
    
       Unless required by applicable law or agreed to in writing, software
       distributed under the License is distributed on an "AS IS" BASIS,
       WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       See the License for the specific language governing permissions and
       limitations under the License.
  • Package Index Owner: addxy
  • DOAP record: geocoder-0.3.63.xml