class LocationIQConverter: def __init__(self): # Create LocationIQ API object to convert places into their coordinates self.geocoder = LocationIQ(ACCESS_TOKEN) #Geolocate the received place returning its latitude and longitude among other properties def place_to_coordinates(self, place=None): if (place == None): return None results = self.geocoder.geocode(place) return results
class LocationIqModel: def __init__(self): """ Create LocationIQ API object to convert places into their coordinates """ self.geocoder = LocationIQ(config.LOCATIONIQ_TOKEN) def get_coordinates(self, place: str, max_tries: int = 10, time_between_tries: int = 1) -> dict: """ Geolocate the received place returning its latitude and longitude among other properties. Arguments: place (:obj:`str`): Plate to convert to coordinates. max_tries (:int, optional): Number of tries to obtain location info. time_between_tries (:int, optional): Time between tries to obtain location info. Returns: :obj:`dict`: contanining the information in matter of geocoding of the given place. """ for i in range(max_tries + 1): try: geocoding_data = self.geocoder.geocode(place) if geocoding_data: geocoding_data = geocoding_data[0] result = { 'lat': float(geocoding_data['lat']), 'lon': float(geocoding_data['lon']), 'address': geocoding_data['address'] } else: result = {'lat': None, 'lon': None, 'address': None} return result except LocationIqRequestLimitExeceeded: time.sleep(time_between_tries) except: pass return None
from locationiq.geocoder import LocationIQ from distance import Haversine import geocoder from flask import Flask, render_template, request, send_from_directory import folium from newsapi import NewsApiClient import pandas as p import os import json import requests from bs4 import BeautifulSoup import numpy as np g = LocationIQ("0e7221f9c35daf") session = {} app = Flask(__name__, "") @app.route("/") @app.route("/about") def about(): return render_template("about.html") @app.route("/news") def home(): n = NewsApiClient(api_key="af7efd1b69c8489fa159bfdc8da6d05a") top = n.get_top_headlines(q="corona", page_size=100) a = top["articles"]
def __init__(self): """ Create LocationIQ API object to convert places into their coordinates """ self.geocoder = LocationIQ(config.LOCATIONIQ_TOKEN)
def __init__(self): # Create LocationIQ API object to convert places into their coordinates self.geocoder = LocationIQ(ACCESS_TOKEN)
import pandas as p from locationiq.geocoder import LocationIQ from math import radians, sin, cos, acos import json geocoder = LocationIQ("e4e5a0627a2ac0") df = p.read_excel('Indian_capitals.xlsx', names=['src', 'des', 'dis'], header=None) d = {} for i in df['src'].unique(): d[i] = [df['des'][j] for j in df[df['src'] == i].index] dr = {} for i in df['des'].unique(): dr[i] = [df['src'][j] for j in df[df['des'] == i].index] for key in d: if key in dr: d[key] = d[key] + dr[key] else: pass for key in dr: if key not in d: d[key] = dr[key] else: pass di = d f = {}
def get_locationiq_geo_coder(): try: apiKey = os.environ["LOCATIONIQ_API_KEY"] return LocationIQ(apiKey) except KeyError: sys.exit('Could not find API key in environment variables!')
from bootstrap_datepicker_plus import DateTimePickerInput from django.contrib import messages from django.contrib.auth.mixins import LoginRequiredMixin from django.core.serializers.json import DjangoJSONEncoder from django.shortcuts import render, redirect, get_object_or_404 from django.utils.translation import gettext_lazy as _ from django.views.generic import FormView from locationiq.geocoder import LocationIQ from django.core import serializers from accounts.models import Event from userprofile.forms import UserProfileForm, DateForm, EventForm, AdvertForm from userprofile.models import userProfile geocoder = LocationIQ('3aca79a02a3732') class indexUserProfile(LoginRequiredMixin, FormView): template_name = 'accounts/profile/change_profile.html' model = userProfile form_class = UserProfileForm def form_valid(self, form): new_model = form.save(commit=False) new_model.user = self.request.user new_model.name = form.cleaned_data['name'] new_model.address = form.cleaned_data['address'] new_model.city = form.cleaned_data['city'] new_model.isDogwalker = form.cleaned_data['isDogwalker'] new_model.lat = convertToLat(form.cleaned_data['address']) new_model.lon = convertToLong(form.cleaned_data['address'])
from PIL import Image import requests from locationiq.geocoder import LocationIQ, LocationIqNoPlacesFound # Constants KEY = 'ENTER LOCATIONIQ TOKEN HERE' SIZE = '800x800' place = input("Enter the place ") if place: # Map zoom zoom = int(input("Enter zoom level: ")) # locationIQ stuff geocoder = LocationIQ(KEY) try: jsondata = geocoder.geocode(place) except LocationIqNoPlacesFound: print("Couldn't find the entered location!") exit(1) # use the lats and longs in json data dict latitude = jsondata[0]['lat'] longitude = jsondata[0]['lon'] static_map = f"https://maps.locationiq.com/v2/staticmap?key={KEY}&markers={latitude},{longitude}|icon:large-red-cutout;&zoom={zoom}&size={SIZE}" # fetch map from static locationiq api map = requests.get(static_map)