Google Maps V3 for IDN
I started using Wordpress less than 1 year ago. Thanks to Wordpress, I could learn how to read some php, css, javascript scripts. I today cannot right new scripts by myself, but someday I might become capable.
The majority of the websites I created use international domain names (IDN). The URL of such domains can be written directly in French or Spanish with accents, in Chinese or Japanese characters (Kanji), in Hindi, in Hebrew, in Arabic…
When I first tried using maps generated by the Google Maps API version 2, I noticed there was a bug and this was related to the fact I was using an IDN. The versions 1 and 2 of the Google Maps API require to ask for an API key in order to include maps in a site. You need one API key for each site.
The problem with IDNs is that it can be written in 2 ways:
- the punycode way
- the UNICODE way
For example, I developped the website avenue-des-champs-élysées.com. The UNICODE writing is avenue-des-champs-élysées but the punycode is xn--avenue-des-champs-lyses-sccd. All IDNs begin by xn-- in punycode.
When a Google map is published on a site, the Google Maps system verifies that the API key corresponds to the domain name. The problem is that the Google Maps system only registers the punycode version (the URL beginning by xn--). But, some browsers show the UNICODE writing instead of the punycode.
Therefore, when the Google Maps system compares the domain name in UNICODE with the API key that was generated from the punycode, an error message pops up each time the website is refreshed. That error message indicates that the API key is not correct.
Fortunately, Google Maps has just released the version 3 which enables to publish maps without any API key.
A new plugin, Simple Google Map, gives the possibility to add maps with the API version 3.
Using a shortcode your insert in your post or page content, you can include a map. In the shortcode you have to give the latitude and the longitude corresponding to the address for which you want to show a map.
In the websites I created, I wanted users who publish their own posts to be able to add maps automatically included in the content from an address rather than from a latitude and a longitude.
I propose here an ameliorated version of Simple Google Map, the Google Maps V3 for IDN.
Actually, the map generating is done in 2 times: geocoding and publication of the map. Geocoding, it is to determine a latitude and a longitude from an address. After the geocoding comes the publication. In the Google Maps V2 version, there was a need for an API key serving to both geocoding and publication.
In fact, in the version V3, if publication does not require any API key, HTTP geocoding still requires one.
Yet, and this is quite important for all the webmasters of websites with IDNs, the utilization of an API key for geocoding does not generate any error on the site.
In the version I propose, you will still need an API key.
I must say that before proposing this version, I contacted the developer of Simple Google Map to propose my version. In spite of the advantage of using directly an address instead of a latitude and a longitude, he did not wish to include the modifications I made since he wishes the users of Simple Google Map not to need for an API key.
I propose my version because I think it will be useful, especilly for IDNs.

do you know of a way to put multiple addresses on one map with your widget? and maybe display some text with each one?
thanks
is it possible to set the size (height and width of the map)?
great work though
thanks for a quick response
Hi Gideon,
Thanks for the comment.
Yes is possible.
Do you want to give the same size and height to all your maps ?
If yes, you go in the code of google-map-idn.php and go to
div id=’GMV’
You change it this way:
div id=’GMV’ style=’width:50%; height:70%;’
And you change the percentage as you want.
Hope it helps you.
I wanted to use your plugin,but our host (1&!) and many other hosts do not allow use of the
get_file_contents
function. I replaced this with code using curl (curl_get_contents) but the map does not render. THe code is in the source, but only a white box shows in the widget sidebar.
Hi Bob,
Actually, the problem comes from Google that accepts only 15000 requests a day from 1 IP.
When you use a shared server instead of a dedicated server, all the websites hosted on the server have the same IP for Google. Therefore the quota of 15000 requests is rapidly reached.
I changed the code a bit so that new custom fields for latitude and longitude are memorized with the post.
I will update the plugin. For the moment, just download the new google-map-idn.php file by clicking on the following link with the right button of your mouse and save it on your computer:
http://www.france-development.com/google-map-idn.php
Then change the content of the file on your server or do it from your editor.
With this new version, the geocoding will be done only once. The latitude and the longitude are kept so that the map will be generated after from the memorized data and not from http request to Google.
As the quota of 15000 may be already reached for today, wait until midnight, so that Google starts again from 0 and go in the pages where you have maps. The maps will then always appear.
Not sure what you did, but you messed up the file to download. I right-clicked and saved file as, but all it contains is code with the following:
Fatal error: Call to undefined function register_activation_hook() in /homez.154/francedeq/www/google-map-idn.php on line 39
Please zip or e-mail me the form to the address in my comment.
Thanks!