Skip to content

Commit

Permalink
CRITICAL UPDATE - Switching Reverse-Geocoder for the GPS
Browse files Browse the repository at this point in the history
Hello Everyone 🎆 ,

Today , Im giving this big update to Switch of the Google Maps API to the GeoPy API.

WHY ? ✈️

As you may notice , Google has changed the way how to use Google Maps as an API.
So , I don't want to pay for a basic features as the GPS , so I'm switching of Geocoders with a totally new API more complete and cool tools and FREE 🍐  .

Go check GeoPy's Github Page here 👍 : https://github.com/geopy/geopy

Thank you to read this , 💞 🌃 🌝 .
  • Loading branch information
Franck1333 committed Oct 21, 2018
1 parent 1be853f commit 085a7a6
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 34 deletions.
45 changes: 45 additions & 0 deletions Example/Geopy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env python
# -*- coding: UTF-8 -*-

#AIDES: https://github.com/geopy/geopy
#AIDES: https://pypi.org/project/geopy/
#AIDES: https://geopy.readthedocs.io/en/stable/index.html?highlight=reverse

import geopy.geocoders #--> sudo pip install geopy
from geopy.geocoders import Nominatim #Nominatim Service

#---
#Cette blibliothèque permet de travailler avec du contenue contenant des accents
import unidecode #--> sudo pip install unicode

#unaccented_location = unidecode.unidecode(location.address)
#---

geolocator = Nominatim(user_agent="GPS-SWAGG") #Utilisation des Services de Reverse-Geocoding de Nominatim, https://nominatim.openstreetmap.org/reverse.php?format=html
#coordonees_GPS = str(Decimal_latitude) +","+ str(Decimal_longitude)
location = geolocator.reverse("47.2224326667, -0.729606666667") #Envoie aux Services de Nominatim les coordonées GPS et reception de la Réponse

unaccented_location = unidecode.unidecode(location.address) #On Retire les Accents de la Réponse de l'API
print("\n") #Saut de ligne
print(unaccented_location) #Affichage de la Réponse (sans accents)
print("\n") #Saut de Ligne
#Potsdamer Platz, Mitte, Berlin, 10117, Deutschland, European Union

print((location.latitude, location.longitude)) #Affichage des coordonées du Lieu indiqué
#(52.5094982, 13.3765983)

print("\n")
#print(location.raw)

Ville = location.raw['address']['town']
Numero_Maison = location.raw['address']['house_number']
Rue = location.raw['address']['road']
Code_Postal = location.raw['address']['postcode']
Pays = location.raw['address']['country']

print(Ville)
print(Numero_Maison)
print(Rue)
print(Code_Postal)
print(Pays)
#{'place_id': '654513', 'osm_type': 'node', ...}
119 changes: 92 additions & 27 deletions GPS/Recuperation_Determination.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
#https://gist.github.com/Lauszus/5785023
#https://raspberry-pi.developpez.com/cours-tutoriels/projets-rpi-zero/traceur-gps/
#https://stackoverflow.com/questions/20169467/how-to-convert-from-longitude-and-latitude-to-country-or-city
#https://github.com/googlemaps/google-maps-services-python
###https://github.com/googlemaps/google-maps-services-python
#AIDES: https://github.com/geopy/geopy
#AIDES: https://pypi.org/project/geopy/
#AIDES: https://geopy.readthedocs.io/en/stable/index.html?highlight=reverse

import serial
import time
Expand All @@ -14,7 +17,19 @@
from urllib2 import urlopen
#from urllib.request import urlopen
import json
import googlemaps #pip install -U googlemaps

#---REVERSE_GEOCODING_GEOPY---
import geopy.geocoders #--> sudo pip install geopy
from geopy.geocoders import Nominatim #Nominatim Service
#---REVERSE_GEOCODING_GEOPY---

#---
#Cette blibliothèque permet de travailler avec du contenue contenant des accents
import unidecode #--> sudo pip install unicode

#unaccented_location = unidecode.unidecode(location.address)
#---

import datetime

#import dot3k.lcd as lcd
Expand Down Expand Up @@ -295,49 +310,99 @@ def retourne_Longitude_Hemisphere():
return Retourne_Longitude_Hemisphere #Retourne la nouvelle Valeur LONGITUDE_HEMISPHERE
#-------------------------------
def determine():
gmaps = googlemaps.Client(key='AIzaSyCbcLmcGDUQlhvZhAkdE0IUFh90rjJ7rrw') #Cle d'acces A.P.I

geolocator = Nominatim(user_agent="GPS-SWAGG") #Utilisation des Services de Reverse-Geocoding de Nominatim, https://nominatim.openstreetmap.org/reverse.php?format=html

coordonees_GPS = str(Decimal_latitude) +","+ str(Decimal_longitude)

print(coordonees_GPS)

location = geolocator.reverse(coordonees_GPS) #Envoie aux Services de Nominatim les coordonées GPS et reception de la Réponse

unaccented_location = unidecode.unidecode(location.address) #On Retire les Accents de la Réponse de l'API
print("\n") #Saut de ligne
print(unaccented_location) #Affichage de la Réponse (sans accents)
print("\n") #Saut de Ligne
#Potsdamer Platz, Mitte, Berlin, 10117, Deutschland, European Union

print((location.latitude, location.longitude)) #Affichage des coordonées du Lieu indiqué
#(52.5094982, 13.3765983)

print("\n")
#print(location.raw)

Ville = location.raw['address']['town'] #Enregistrement de la Ville depuis la version "RAW" du Service Nominatim
Numero_Maison = location.raw['address']['house_number'] #Enregistrement du Numéro de Rue depuis la version "RAW" du Service Nominatim
Rue = location.raw['address']['road'] #Enregistrement de la Rue depuis la version "RAW" du Service Nominatim
Code_Postal = location.raw['address']['postcode'] #Enregistrement du Code Postal depuis la version "RAW" du Service Nominatim
Pays = location.raw['address']['country'] #Enregistrement du Pays depuis la version "RAW" du Service Nominatim

print(Ville) #Affichage de la Ville
print(Numero_Maison) #Affichage du Numéro de Positionnement dans la Rue
print(Rue) #Affichage du Nom de la Rue
print(Code_Postal) #Affichage du Code Postal
print(Pays) #Affichage du Pays
#{'place_id': '654513', 'osm_type': 'node', ...} #Exemple du format des données reçu enregistrer dans "location.raw"


#---------------------------------------------
#gmaps = googlemaps.Client(key='AIzaSyCbcLmcGDUQlhvZhAkdE0IUFh90rjJ7rrw') #Cle d'acces A.P.I

#etat_trame() #Validation de la conformite de la Trame NMEA <--

# Look up an address with reverse geocoding
reverse_geocode_result = gmaps.reverse_geocode((Decimal_latitude, Decimal_longitude)) #Envoie et Recuperation des Donnees
# Look up an address with reverse geocoding
#reverse_geocode_result = gmaps.reverse_geocode((Decimal_latitude, Decimal_longitude)) #Envoie et Recuperation des Donnees

#Accessing the needed part of the response
#reverse_geocode_result[0] # This is a dict
#reverse_geocode_result[0]['address_components'][3]['long_name'] # Return La Region
#reverse_geocode_result[0]['address_components'][4]['long_name'] # Return country
#reverse_geocode_result[0]['address_components'][2]['long_name'] # Return sublocality
#reverse_geocode_result[0]['address_components'][1]['long_name'] # Return route
#reverse_geocode_result[0]['address_components'][0]['long_name'] # Return street number
#Accessing the needed part of the response
#reverse_geocode_result[0] # This is a dict
#reverse_geocode_result[0]['address_components'][3]['long_name'] # Return La Region
#reverse_geocode_result[0]['address_components'][4]['long_name'] # Return country
#reverse_geocode_result[0]['address_components'][2]['long_name'] # Return sublocality
#reverse_geocode_result[0]['address_components'][1]['long_name'] # Return route
#reverse_geocode_result[0]['address_components'][0]['long_name'] # Return street number

print("On se trouve a :")
#print("On se trouve a :")
#print(reverse_geocode_result) Format JSON

resultat_Ville = reverse_geocode_result[0]['formatted_address'] #STRING LOCALISATION DETERMINE
print (resultat_Ville) #JSON Parse (trie)
#resultat_Ville = reverse_geocode_result[0]['formatted_address'] #STRING LOCALISATION DETERMINE
#print (resultat_Ville) #JSON Parse (trie)

return resultat_Ville #RETOURNE LE STRING DE LA LOCALISATION DETERMINE
#return resultat_Ville #RETOURNE LE STRING DE LA LOCALISATION DETERMINE
#return reverse_geocode_result #RETOURNE LA LOCALISATION OBTENUE AU FORMAT JSON
#---------------------------------------------
#-------------------------------

#-------------------------------
#NOUS INDICONS UNIQUEMENT LA VILLE ICI
def determine_less():
etat_trame() #Validation de la conformite de la Trame NMEA <--

gmaps = googlemaps.Client(key='AIzaSyCbcLmcGDUQlhvZhAkdE0IUFh90rjJ7rrw') #Cle d'acces A.P.I
geolocator = Nominatim(user_agent="GPS-SWAGG") #Utilisation des Services de Reverse-Geocoding de Nominatim, https://nominatim.openstreetmap.org/reverse.php?format=html

# Look up an address with reverse geocoding
reverse_geocode_result = gmaps.reverse_geocode((Decimal_latitude, Decimal_longitude)) #Envoie et Recuperation des Donnees

print("Ici c'est :")
#print(reverse_geocode_result) Format JSON
coordonees_GPS = str(Decimal_latitude) +","+ str(Decimal_longitude)

resultat_Ville_less = reverse_geocode_result[0]['address_components'][2]['long_name'] #STRING LOCALISATION DETERMINE
print (resultat_Ville_less) #JSON Parse (trie)

return resultat_Ville_less #RETOURNE LE STRING DE LA LOCALISATION DETERMINE
#return reverse_geocode_result #RETOURNE LA LOCALISATION OBTENUE AU FORMAT JSON
print(coordonees_GPS)

location = geolocator.reverse(coordonees_GPS) #Envoie aux Services de Nominatim les coordonées GPS et reception de la Réponse

unaccented_location = unidecode.unidecode(location.address) #On Retire les Accents de la Réponse de l'API
print("\n") #Saut de ligne
print(unaccented_location) #Affichage de la Réponse (sans accents)
print("\n") #Saut de Ligne
#Potsdamer Platz, Mitte, Berlin, 10117, Deutschland, European Union

print((location.latitude, location.longitude)) #Affichage des coordonées du Lieu indiqué
#(52.5094982, 13.3765983)

print("\n")
#print(location.raw)

Ville = location.raw['address']['town'] #Enregistrement de la Ville depuis la version "RAW" du Service Nominatim
Pays = location.raw['address']['country'] #Enregistrement du Pays depuis la version "RAW" du Service Nominatim

print(Ville) #Affichage de la Ville
print(Pays) #Affichage du Pays
#{'place_id': '654513', 'osm_type': 'node', ...} #Exemple du format des données reçu enregistrer dans "location.raw"
#-------------------------------
#-------------------------------
def lecture_serie():
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# TravelKit_RPI
# TravelKit_RPI

This Project give you useful details about the environement where you are by Using an USB GPS and some API with an Internet Connection.

Expand Down Expand Up @@ -31,7 +31,7 @@ A screen (Diplayotron 3000 or other Displays)
-sys
-from urllib2 import urlopen
-json
-googlemaps (API GOOGLEMAPS pip install -U googlemaps)
-geopy (API GEOPY pip install geopy)
-datetime
-unicodedata
-requests
Expand Down Expand Up @@ -81,10 +81,10 @@ When you did it , you will have to launch the file called "setup.py" to install
sudo pip install pyowm
```

#### The Google Maps API :
#### The GeoPy API :

```
sudo pip install -U googlemaps
sudo pip install geopy
```

## Run
Expand Down Expand Up @@ -172,7 +172,7 @@ Boussole.py : Get Compass data by using the "Recuperation_Determination.py"
GPSoI.py : Get the location of the user's IP Adress by using the *IPSTACK.COM API*
Meteo.py : Get the Weather's data by using *pyown API* and the "Recuperation_Determination.py" file's data
Meteo_3h.py : Get the Weather's data by using *pyown API* and the "Recuperation_Determination.py" file's data with a forecast of 3 Hours
Recuperation_Determination.py : Get information come from the GPS USB stick and determinate the location with the *Google Maps API*
Recuperation_Determination.py : Get information come from the GPS USB stick and determinate the location with the *GeoPy API*
Recuperation_FR_GPS.py : Allow to display the information come from the GPS USB stick in French
```
#### Files in "/TravelKit_RPI/START/"
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@

setup(
name='TravelKit_RPI',
version="1.13",
version="1.73",
author='Franck Rochat',
author_email='rochat.franck@gmail.com',
description='This Project give you useful details about the environement where you are by Using an USB GPS and some API with an Internet Connection',
url='https://github.com/Franck1333/TravelKit_RPI',
license='lgpl',
packages=find_packages(),
include_package_data=False,
install_requires=["pyowm","googlemaps"], #Get the Dependencies from Pypi (pip install)
install_requires=["pyowm","geopy"], #Get the Dependencies from Pypi (pip install)
dependency_links=['https://github.com/pimoroni/displayotron'], #Get the Dependencies via HTTP(s)
)

0 comments on commit 085a7a6

Please sign in to comment.