{"size": 721, "ext": "js", "max_stars_repo_path": "src/api.js", "max_stars_repo_name": "r-soga/nuxt-simple-geocoding-ja", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/api.js", "max_issues_repo_name": "r-soga/nuxt-simple-geocoding-ja", "max_issues_repo_issues_event_min_datetime": "2021-05-05T09:24:09.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-26T07:22:46.000Z", "max_forks_repo_path": "src/api.js", "max_forks_repo_name": "r-soga/nuxt-community-geocoder", "max_forks_repo_forks_event_min_datetime": "2021-09-25T05:38:37.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-25T05:38:37.000Z"}
{"max_stars_count": null, "max_issues_count": 5, "max_forks_count": 1, "avg_line_length": 25.75, "max_line_length": 70, "alphanum_fraction": 0.6074895978}
const enrichment = require('./imi-enrichment-address/main').enrichment
const fetch = require('node-fetch')

let getLatLng = (str, callback, errorCallback = () => {}) => {
  try {
    let code = enrichment(str)

    const prefCode = code.substr(0, 2)
    const cityCode = code.substr(0, 5)

    const base = 'https://community-geocoder.geolonia.com/api'
    const api = `${base}/${prefCode}/${cityCode}/${code}.json`

    fetch(api).then(res => {
      return res.json()
    }).then(json => {
      json.code = code
      callback(json)
    }).catch(() => {
      const e = new Error('見つかりませんでした。住所を修正して、もう一度お試しください。')
      errorCallback(e)
    })
  } catch (e) {
    errorCallback(e)
  }
}

exports.getLatLng = getLatLng