Overview

I had the opportunity to try out geocoding libraries, so here are my notes.

Target

This time, we will use the following text as our target:

岡山市旧御野郡金山寺村。現在の岡山市金山寺。市の中心部からは直線で北方約一〇キロを隔てた金山の中腹にある。 (Okayama City, former Mino District, Kinzanji Village. Currently Kinzanji, Okayama City. Located on the hillside of Kanayama, approximately 10 kilometers north of the city center in a straight line.)

Tool 1: Jageocoder - A Python Japanese geocoder

First, let’s try “Jageocoder.”

https://t-sagara.github.io/jageocoder/

Here is a source code example:

import json
import jageocoder
jageocoder.init(url='https://jageocoder.info-proto.com/jsonrpc')

results = jageocoder.search('岡山市旧御野郡金山寺村。現在の岡山市金山寺。市の中心部からは直線で北方約一〇キロを隔てた金山の中腹にある。')
print(json.dumps(results, indent=2, ensure_ascii=False))

The following result was obtained:

{
  "matched": "岡山市",
  "candidates": [
    {
      "id": 197677508,
      "name": "岡山市",
      "x": 133.91957092285156,
      "y": 34.65510559082031,
      "level": 3,
      "priority": 1,
      "note": "geoshape_city_id:33100A2009/jisx0402:33100/jisx0402:33201",
      "fullname": [
        "岡山県",
        "岡山市"
      ]
    }
  ]
}

This may be a configuration issue, but we only got information up to Okayama City.

You can also try it via the web UI at the following page:

https://jageocoder.info-proto.com/

Tool 2: GeoNLP

The following page provides a web UI for testing:

https://geonlp.ex.nii.ac.jp/jageocoder/demo/

Since GeoNLP also uses jageocoder internally, similar results were obtained.

I also tried the “Text Geotagging (GeoNLP) Demo” at the following page:

https://geonlp.ex.nii.ac.jp/demo/

Multiple place names were extracted from the input text.

Tool 3: Google Maps Platform API

Finally, let’s try using the Google Maps Platform API.

https://developers.google.com/maps?hl=ja

import requests
import os
from dotenv import load_dotenv

load_dotenv(verbose=True)

def geocode_address(address, api_key):
    url = "https://maps.googleapis.com/maps/api/geocode/json"
    params = {
        "address": address,
        "key": api_key,
        "language": "ja"  # Set to return results in Japanese
    }
    response = requests.get(url, params=params)
    if response.status_code == 200:
        data = response.json()
        if data['status'] == "OK":
            result = data['results'][0]
            location = result['geometry']['location']
            print(f"Address: {result['formatted_address']}")
            print(f"Latitude: {location['lat']}, Longitude: {location['lng']}")
        else:
            print(f"Error: {data['status']}")
    else:
        print(f"HTTP Error: {response.status_code}")

# Usage example
API_KEY = os.getenv("API_KEY")

address = "岡山市旧御野郡金山寺村。現在の岡山市金山寺。市の中心部からは直線で北方約一〇キロを隔てた金山の中腹にある。"
geocode_address(address, API_KEY)

The following result was obtained:

Address: 日本、〒701-2151 岡山県岡山市北区金山寺
Latitude: 34.7375568, Longitude: 133.946063

Summary

There are many other geocoding libraries available, but I hope this serves as a useful reference.