Skip to content

Instantly share code, notes, and snippets.

@thany
Last active May 22, 2025 11:43
Show Gist options
  • Save thany/a21281f2d9847d1c94c8c9d8a2447968 to your computer and use it in GitHub Desktop.
Save thany/a21281f2d9847d1c94c8c9d8a2447968 to your computer and use it in GitHub Desktop.
Get Denso Mapcode from Denso server using a bash command
wget http://post.denso-communications.jp/dn/navicon_start.php --method=POST --body-data="lat=35.872722875676274&lng=139.73869658316153" -O - -q | grep -Po '(?<=id="mapcode">)([^<]*)'
@thany
Copy link
Author

thany commented Aug 28, 2019

Disclaimer

Denso Co Ltd keep for themselves how to generate these codes, so using their server seems okay to me. Denso Mapcodes are widely used in Japan, especially in car satnavs, so obtaining mapcodes ought to be as free as free speech. Well, it bloody sure isn't. I understand that Japanese businesses do not yet fully understand the appeal of being open, so I suppose scripting it is the next best thing. They don't even provide the simplest of API's, so the second-best thing would be to scrape a webpage they return when requesting a code. And this command does exactly that.

References

https://en.wikipedia.org/wiki/Denso_mapcode
For more information on Denso Mapcode

Visually get mapcodes

http://japanmapcode.com/en
Does use its own proper JSON API, but since it's a personal project, I rather not "punish" him for Denso's fault of keeping everything a secret.

@bespired
Copy link

bespired commented May 6, 2025

I found a Chinese site that had info about Mapion
https://josephliu1206.pixnet.net/blog/post/25753253

Mapion seem to have an algorithm to find the japan-mapcode. Example:
https://www.mapion.co.jp/f/mmail/send_mobile/SendMobile_map.html?lon=130.99586961830084&lat=34.272715550129554

Still not ideal.

I dont know if scraping is what we want...
Maybe figure out if there is any logic in the Zone/Block/Unit blocks.
Maybe its just counted 30x30 = 900 for Block and Unit ? S core seems weird... looks like 9hor 9vert ?
https://www.denso-solution.com/mapcode/en/whats.html

Im going to look into this... Maybe the blue japan is giving us a hint on the Zones...
(Can't find any sense in it just yet)

This is an interesting site:
https://saibara.sakura.ne.jp/map/convgeo.cgi

@thany
Copy link
Author

thany commented May 6, 2025

There's definitely logic, but it's also littered with exceptions. Especially the first block of digits is often tied to a city or region, rather than a translation from geographic coordinates. I think only the last two digits (after the asterisk) are truly and always coordinates-based, as the graphic explains as well.

And because of this, I gave up on trying to reverse-engineer an algorithm of sorts, because exceptions can make it really annoying (if not impossible) to get accurate results algorithmically.

@bespired
Copy link

bespired commented May 8, 2025

Well, if anyone is interested. I've scraped the zones from saibara.sakura.ne.jp/map/convgeo.cgi
google drive: denso-mapcode-zones.js
As it turns out they are a bit off... Looking into that.
I'm going to check them on mapion, but random checks show it looks okay.
Next is figure out the Block/Unit/S-core

denso-mapcode-zones

@thany
Copy link
Author

thany commented May 9, 2025

I'm seeing a lot of overlaps. I wonder how those are handled. Maybe it's just simply the lower zone number get prioritised.

Also, kudos for visualising the zones on a map. Definitely a useful way to ensure/verify everything is covered.

@bespired
Copy link

bespired commented May 9, 2025

We are getting there... πŸ˜„
Still not seeing how the overlap actually matters.. Some places even have 3 overlapping zones.
All these mapcodes seem to point to the same lat/lon when reverse searching.
The code I have now picks the highest number by accident because the code is not very smart yet.
Still trying to figure out how it actually works.
I did find I scrapped the zones to tight. They should be 9m bigger...

Good to see in overlapping zones:

55-error

For putting the mapcode in a car navi these differences don't really matter I think.
And I don't know if a car navi in Japan is okay with wrong zones.
But yeah,... needs to be fixed just to be more neat.
More later.

I think I will create a client-side (Vite-Vue3-Leafjs-OpenStreetMap) solution.
And I don't know if Denso is going to be happy with their "secret" zone data on the clients browser.

@bespired
Copy link

I've made a story on medium about my adventures with mapcode:
https://bespired.medium.com/adventures-in-denso-japan-mapcode-6743694d26a8
with a repo in github https://github.com/bespired/mapcode

@thany
Copy link
Author

thany commented May 21, 2025

Very cool! There are a few typos, but that's okay. Maybe extend the article to answer the seemingly important questions in the comment. But other than that I think your contribution is going to be really helpful 😎 I really respect how you allowed yourself to "bite" into this issue and not let go until you found a suitable solution πŸ‘πŸ»

@bespired
Copy link

Thanks Martijn.
Still need to check if any random coordinate actually gives the correct answer.
But I found something I don't really understand yet.
Apparently the Longitude/Latitude of Japan are not the same as the Longitude/Latitude of the world (???)

Screenshot 2025-05-22 at 13 30 38

So putting global lon/lat into Mapion doesn't actually works. Because they are not the same as the Japanese lat/lon... I don't know, I find this very confusing.

Screenshot 2025-05-22 at 13 35 19

Apparently Japan has earthquake shifted lat/lon?
https://www.fig.net/resources/proceedings/fig_proceedings/fig_2002/Ts5-5/TS5_5_ishihara.pdf

This is all far beyond my comprehension. Pretty nuts if you ask me...
And way beyond my initial wish to just have a Japan Mapcode from under my cursor.

Screenshot 2025-05-22 at 13 40 53

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment