How to use the googlemaps.Client function in googlemaps

To help you get started, we’ve selected a few googlemaps examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github googlemaps / google-maps-services-python / test / test_roads.py View on Github external
def test_clientid_not_accepted(self):
        client = googlemaps.Client(client_id="asdf", client_secret="asdf")

        with self.assertRaises(ValueError):
            client.speed_limits("foo")
github googlemaps / google-maps-services-python / test / test_client.py View on Github external
def test_auth_url_with_channel(self):
        client = googlemaps.Client(key="AIzaasdf",
                                   client_id="foo",
                                   client_secret="a2V5",
                                   channel="MyChannel_1")

        # Check ordering of parameters + signature.
        auth_url = client._generate_auth_url("/test",
                                             {"param": "param"},
                                             accepts_clientid=True)
        self.assertEqual(auth_url, "/test?param=param"
                            "&channel=MyChannel_1"
                            "&client=foo"
                            "&signature=OH18GuQto_mEpxj99UimKskvo4k=")

        # Check if added to requests to API with accepts_clientid=False
        auth_url = client._generate_auth_url("/test",
                                             {"param": "param"},
github googlemaps / google-maps-services-python / test / test_timezone.py View on Github external
def setUp(self):
        self.key = "AIzaasdf"
        self.client = googlemaps.Client(self.key)
github peeringdb / peeringdb / peeringdb_server / management / commands / pdb_geosync.py View on Github external
def handle(self, *args, **options):
        self.commit = options.get("commit", False)
        reftag = options.get("reftag")
        limit = options.get("limit")
        if reftag.find(".") > -1:
            reftag, _id = reftag.split(".")
        else:
            _id = 0
        self.gmaps = googlemaps.Client(API_KEY, timeout=5)
        self.sync(reftag, _id, limit=limit)
github FoglyOgly / Meowth / meowth / exts / map / map_cog.py View on Github external
from pytz import timezone
import io
import codecs
from math import radians, degrees, sqrt, ceil
import csv
from urllib.parse import quote_plus
import googlemaps
import re
import requests
from typing import List
import tempfile

from .map_info import gmaps_api_key
from .errors import *

gmaps = googlemaps.Client(key=gmaps_api_key)


class ReportChannel():
    def __init__(self, bot, channel):
        self.bot = bot
        self.channel = channel

    def __eq__(self, other):
        return self.channel.id == other.channel.id

    @property
    def _data(self):
        channel_query = self.bot.dbi.table('report_channels').query()
        _data = channel_query.where(channelid=self.channel.id)
        return _data
github mricon / ingress-fieldplan / lib / maxfield.py View on Github external
# Do we have a gmaps key?
    if gmapskey is None:
        # Do we have a cached copy in the cache?
        if 'clientkey' in _gmap_cache_db:
            gmapskey = _gmap_cache_db['clientkey']
    else:
        # save it in the cache db if not present or different
        if 'clientkey' not in _gmap_cache_db or _gmap_cache_db['clientkey'] != gmapskey:
            logger.info('Caching google maps key for future lookups')
            _gmap_cache_db['clientkey'] = gmapskey

    gmaps = None
    if gmapskey:
        import googlemaps
        gmaps = googlemaps.Client(key=gmapskey)
        logger.info('Generating the distance matrix using Google Maps API, may take a moment')
    else:
        logger.info('Generating the distance matrix')

    a = combined_graph.copy()
    n = a.order()
    logger.debug('n=%s', n)

    # We consider any direct distance shorter than 40m as effectively 0,
    # since the agent doesn't need to travel to access both portals.
    for p1 in range(n):
        matrow = list()
        matrow_dur = list()
        direct_matrow = list()
        for p2 in range(n):
            # Do direct distance first
github all-of-us / raw-data-repository / rest-api / tools / import_organizations.py View on Github external
def _get_lat_long_for_site(self, address_1, city, state):
    self.full_address = address_1 + ' ' + city + ' ' + state
    try:
      self.api_key = os.environ.get('API_KEY')
      self.gmaps = googlemaps.Client(key=self.api_key)
      try:
        geocode_result = self.gmaps.geocode(address_1 + '' +  city + ' ' +  state)[0]
      except IndexError:
        self.errors.append('Bad address for {}, could not geocode.'.format(self.full_address))
        return None, None
      if geocode_result:
        geometry = geocode_result.get('geometry')
        if geometry:
          location = geometry.get('location')
        if location:
          latitude = location.get('lat')
          longitude = location.get('lng')
          return latitude, longitude
        else:
          logging.warn('Can not find lat/long for %s', self.full_address)
          self.errors.append('Can not find lat/long for {}'.format(self.full_address))
github tomslee / airbnb-data-collection / reverse_geocode.py View on Github external
def reverse_geocode(config, location):
    """
    Return address information from the Google API as a Location object for a given lat lng
    """
    gmaps = googlemaps.Client(key=config.GOOGLE_API_KEY)
    # Look up an address with reverse geocoding
    # lat = 41.782
    # lng = -72.693
    lat = location.lat_round
    lng = location.lng_round
    results = gmaps.reverse_geocode((lat, lng))

    # Parsing the result is described at
    # https://developers.google.com/maps/documentation/geocoding/web-service-best-practices#ParsingJSON

    json_file = open("geocode.json", mode="w", encoding="utf-8")
    json_file.write(json.dumps(results, indent=4, sort_keys=True))
    json_file.close()
    #  In practice, you may wish to only return the first result (results[0])

    for result in results:
github uno-isqa-8950 / uno-cpi / projects / views.py View on Github external
from django.forms import inlineformset_factory, modelformset_factory
from .filters import SearchProjectFilter
import googlemaps
from shapely.geometry import shape, Point
import pandas as pd
import json
from django.db.models import Sum
import datetime
from django.conf import settings
from googlemaps import Client
# The imports below are for running sql queries for AllProjects Page
from django.db import connection
from UnoCPI import sqlfiles

sql=sqlfiles
gmaps = Client(key=settings.GOOGLE_MAPS_API_KEY)


@login_required()
@communitypartner_required()
def communitypartnerhome(request):
    usertype = User.objects.get(is_communitypartner=True)

#    if usertype.is_communitypartner == True:
    return render(request, 'community_partner_home.html',
                  {'communitypartnerhome': communitypartnerhome,'usertype':usertype})


@login_required()
def myProjects(request):
    projects_list=[]
    data_definition=DataDefinition.objects.all()