gp

geolocation-python

Geolocation is simple google maps api for python users. This application allows you to get information about given location Application returns such information as: country, city, route/street, street number, reverse geocode, lat and lng, travel distance and time for a matrix of origins and destinations.

Showing:

Popularity

Downloads/wk

0

GitHub Stars

80

Maintenance

Last Commit

6yrs ago

Contributors

7

Package

Dependencies

0

License

Copyright (c) 2014, Sławomir Kabik All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the {organization} nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Categories

Readme

What is Geolocation 0.2.2?

Alt text   PyPI version    Gitter

Geolocation is a simple and clever application which uses google maps api.

  1. Geocode Module allows you to easily and quickly get information about given location.

Geocode Module returns such information as:

  • country,
  • country short form,
  • city,
  • route/street,
  • street number,
  • postal code,
  • formatted address,
  • administrative areas,
  • lat,
  • lng
  1. Distance Module allows you to get information about travel distance and time for a matrix of origins and destinations.

Distance Module returns such information as:

  • origin address
  • destination address
  • duration
  • distance
    • kilometers
    • meters
    • miles

Python2 or Python3?

Both!. Currently it supports python 2.7, 3.3 and 3.4.

What do You need?

To use this application you need to have Google API key. Google Maps Documentation -- Geocoding

  1. Open APIs console.

    Alt text

  2. Turn On Geocode API.

    Alt text

  3. Turn On Distance Matrix API.

    Alt text

  4. Get your API Key.

    Alt text

How to install it?

pip install geolocation-python

How to use Geocode Module?

# -*- coding: utf-8 -*-

from geolocation.main import GoogleMaps

address = "New York City Wall Street 12"

google_maps = GoogleMaps(api_key='your_google_maps_key') 

location = google_maps.search(location=address) # sends search to Google Maps.

print(location.all()) # returns all locations.

my_location = location.first() # returns only first location.

print(my_location.city)
print(my_location.route)
print(my_location.street_number)
print(my_location.postal_code)

for administrative_area in my_location.administrative_area:
    print("{}: {} ({})".format(administrative_area.area_type, 
                               administrative_area.name, 
                               administrative_area.short_name))

print(my_location.country)
print(my_location.country_shortcut)

print(my_location.formatted_address)

print(my_location.lat)
print(my_location.lng)

# reverse geocode

lat = 40.7060008
lng = -74.0088189

my_location = google_maps.search(lat=lat, lng=lng).first()

How to use Distance Module?

Mode parameter — specifies the mode of transport to use when calculating directions.

Valid values are:

  • driving (default) indicates standard driving directions using the road network.
  • walking requests walking directions via pedestrian paths & sidewalks (where available).
  • bicycling requests bicycling directions via bicycle paths & preferred streets (currently only available in the US and some Canadian cities).
  • transit requests distance calculation via public transit routes (where available).

Avoid parameter - Directions may be calculated that adhere to certain restrictions. Restrictions are indicated by use of the avoid parameter, and an argument to that parameter indicating the restriction to avoid.

The following restrictions are supported:

  • avoid=tolls
  • avoid=highways
  • avoid=ferries
# -*- coding: utf-8 -*-

from geolocation.main import GoogleMaps
from geolocation.distance_matrix.client import DistanceMatrixApiClient

origins = ['rybnik', 'oslo']
destinations = ['zagrzeb']

google_maps = GoogleMaps(api_key='your_google_maps_key')

items = google_maps.distance(origins, destinations).all()  # default mode parameter is DistanceMatrixApiClient.MODE_DRIVING.

for item in items:
    print('origin: %s' % item.origin)
    print('destination: %s' % item.destination)
    print('km: %s' % item.distance.kilometers)
    print('m: %s' % item.distance.meters)
    print('miles: %s' % item.distance.miles)
    print('duration: %s' % item.duration)  # returns string.
    print('duration datetime: %s' % item.duration.datetime)  # returns datetime.
    
    # you can also get items from duration, returns int() values.
    print('duration days: %s' % item.duration.days)
    print('duration hours: %s' % item.duration.hours)
    print('duration minutes: %s' % item.duration.minutes)
    print('duration seconds: %s' % item.duration.seconds)

Mode Bicycling:

items = google_maps.distance(origins, destinations, DistanceMatrixApiClient.MODE_BICYCLING).all()

for item in items:
    print('origin: %s' % item.origin)
    print('destination: %s' % item.destination)
    print('km: %s' % item.distance.kilometers)
    print('m: %s' % item.distance.meters)
    print('miles: %s' % item.distance.miles)
    print('duration: %s' % item.duration)

Mode Walking:

items = google_maps.distance(origins, destinations, DistanceMatrixApiClient.MODE_WALKING).all()

for item in items:
    print('origin: %s' % item.origin)
    print('destination: %s' % item.destination)
    print('km: %s' % item.distance.kilometers)
    print('m: %s' % item.distance.meters)
    print('miles: %s' % item.distance.miles)
    print('duration: %s' % item.duration)

Mode Transit:

items = google_maps.distance(origins, destinations, DistanceMatrixApiClient.MODE_TRANSIT).all()

for item in items:
    print('origin: %s' % item.origin)
    print('destination: %s' % item.destination)
    print('km: %s' % item.distance.kilometers)
    print('m: %s' % item.distance.meters)
    print('miles: %s' % item.distance.miles)
    print('duration: %s' % item.duration)

Mode Highway:

items = google_maps.distance(origins, destinations, avoid=DistanceMatrixApiClient.AVOID_HIGHWAYS).all()

for item in items:
    print('origin: %s' % item.origin)
    print('destination: %s' % item.destination)
    print('km: %s' % item.distance.kilometers)
    print('m: %s' % item.distance.meters)
    print('miles: %s' % item.distance.miles)
    print('duration: %s' % item.duration)

Avoid Ferries:

items = google_maps.distance(origins, destinations, avoid=DistanceMatrixApiClient.AVOID_FERRIES).all()

for item in items:
    print('origin: %s' % item.origin)
    print('destination: %s' % item.destination)
    print('km: %s' % item.distance.kilometers)
    print('m: %s' % item.distance.meters)
    print('miles: %s' % item.distance.miles)
    print('duration: %s' % item.duration)

Avoid Tolls:

items = google_maps.distance(origins, destinations, avoid=DistanceMatrixApiClient.AVOID_TOLLS).all()

for item in items:
    print('origin: %s' % item.origin)
    print('destination: %s' % item.destination)
    print('km: %s' % item.distance.kilometers)
    print('m: %s' % item.distance.meters)
    print('miles: %s' % item.distance.miles)
    print('duration: %s' % item.duration)

More examples you should find here.

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial