Issue reverse geocoding in Japanese with Python Google Maps API

The beginning is from "latitude / longitude"

As I happened to fix VBA in Excel of the data processing team at work, I was asked, "Mr. atsukinov, have you ever used API in VBA?" "Well, I've never used it. What's wrong?" "I'm using the Google Map API to look up an address from latitude and longitude in VBA, but it doesn't work very well ..." "How" That's why I was shown the code screen *** (I don't understand at all) *** That was an honest impression. I've only used the flickr API for downloading images according to the tutorial, but I'm not using the API in the first place! !! "By the way, how much do you process that data?" *** "80,000 lines" *** Oh... You'll definitely want to use APIs and other features like that. But honestly, I thought it would be easier to handle it with Python if I used the API. "For now, I'll try to find out if I can do anything with Python." That said, I decided to look into the Google Maps API first.

I'm tired of seeing Geocoding articles! !!

That's why I tried to google immediately, but apparently it turned out that it is "reverse-Geocoding" to detect the address from "latitude / longitude". Searching for an address, latitude / longitude from a property name or name seems to be ordinary "geocoding". Unfortunately, there weren't many articles that hit this "reverse geocoding," and I couldn't find the code I was looking for. *** I'm tired of seeing regular geocoding articles! !! *** *** Furthermore, even if a code similar to that of reverse geocoding was on board, the problem was that the address obtained was written in English, that is, in the form of address → prefecture, and was written in alphabets. For example, if you look at "Tokyo Tower" ・ 4-2-8 Shibakoen, Minato-ku, Tokyo 105-0011 Is not displayed ・ 4-2-8, Shiba Park, Minatoku, Tokiyo It will be written like this. This would be a problem for the next person to read the address, so I managed to find a way to write it in Japanese. *** And found ***

I will post the code below, so I hope you find it helpful. [Easy-to-understand explanation (Geocoder / Googlemaps)](https://qiita.com/yoshi_yast/items/bb75d8fceb712f1f49d1#%E3%82%84%E3%81%A3%E3%81% 9F% E3% 81% 93% E3% 81% A8% E3% 82% B3% E3% 83% BC% E3% 83% 89)

Find an address in Japanese by reverse geocoding (latitude / longitude)

import googlemaps

#Store the API key obtained for GoogleMapsAPI in a variable
Key = XXXXX

#Returns API key for Google Maps API
gmaps = googlemaps.Client(key=Key)

#Store some latitude / longitude in the list
list = [
    "35.65858645, 139.745440057962", #Tokyo Tower
    "35.71005425, 139.810714099926" #Tokyo Sky Tree
]

#Search for addresses in order from the list
for i in list:
    results = gmaps.reverse_geocode((i), language='ja')
    add = [d.get('formatted_address') for d in results]
    print(add[1])

#=>Japan, 〒105-0011 4-2-8 Shibakoen, Minato-ku, Tokyo
#=>Japan, 〒131-0045 1-1-83 Oshiage, Sumida-ku, Tokyo

The problem is that, as it is, there is a slight extra character "Japan," at the beginning of the sentence. I'll modify the code a bit so that I can write this in a slice from the middle.

for i in list:
    results = gmaps.reverse_geocode((i), language='ja')
    add = [d.get('formatted_address') for d in results]
    Jusho = add[1]
    print(Jusho[3:])

#=>〒105-0011 4-2-8 Shibakoen, Minato-ku, Tokyo
#=>〒131-0045 1-1-83 Oshiage, Sumida-ku, Tokyo

Yeah, it's a great work. It is the shape that I was looking for. However, the problem seems to be that the Google Maps API can access up to 40,000 free APIs a month (source. = ja))) Well, there may not be many heavy users who exceed that, but if you exceed it, you will be charged, so keep in mind.

Recommended Posts

Issue reverse geocoding in Japanese with Python Google Maps API
Explains JavaScript of Google Maps Geocoding API
Get Google Fit API data in Python
Geocoding in python
Play with Google Spread Sheets in python (OAuth)
Display Google Maps API with Rails and pin display
Run Google Analytics API (core v3) in python
Create an image with characters in python (Japanese)
Japanese output in Python
C API in Python 3
Reverse strings in Python
[GCP] [Python] Deploy API serverless with Google Cloud Functions!
Upload JPG file using Google Drive API in Python
Playing with a user-local artificial intelligence API in Python
Create a tweet heatmap with the Google Maps API
Japanese output when dealing with python in visual studio
Hit Mastodon's API in Python
Sonic geocoding with Python geocoder 1.4.0
Use Trello API with python
Send Japanese email with Python3
I wrote python in Japanese
Scraping with selenium in Python
Working with LibreOffice in Python
Scraping with chromedriver in python
Use Twitter API with Python
Debugging with pdb in Python
How to extract any appointment in Google Calendar with Python
Study Python with Google Colaboratory
Working with sounds in Python
Scraping with Selenium in Python
Scraping with Tor in Python
Web API with Python + Falcon
Tweet with image in Python
[SAP CP] Web API created with python in CF environment
Combined with permutations in Python
Japanese morphological analysis with Python
[LINE Messaging API] Issue channel access token v2.1 in Python
Play RocketChat with API / Python
Get data from analytics API with Google API Client for python
Blender Python API in Houdini (Python 3)
Access Google Drive with Python
Use subsonic API with python3
I understand Python in Japanese!
Google Drive Api Tips (Python)
Play with YouTube Data API v3 using Google API Python Client
Get Japanese synonyms in Python
Python: Extract file information from shared drive with Google Drive API
Create an application that just searches using the Google Custom Search API with Python 3.3.1 in Bottle
How to not escape Japanese when dealing with json in python
Cloud DevOps Cookbook Part 4-Explore DevOps DirectMail in Python with REST API
Regularly upload files to Google Drive using the Google Drive API in Python
Firebase Authentication token issuance in Python and token verification with Fast API
[SEO] Flow / sample code when using Google Analytics API in Python
Number recognition in images with Python
Testing with random numbers in Python
Getting the arXiv API in Python
Create Awaitable with Python / C API
GOTO in Python with Sublime Text 3
Working with LibreOffice in Python: import
Get reviews with python googlemap api
Hit the Sesami API in Python