Adding map links and a small map to any text using JavaScript – addmap.js
Friday, January 29th, 2010 at 3:50 pmAs part of a larger article, I am currently building some tools that use geographical information. The first one is a pure JavaScript solution to link locations in a text to Google Maps and to show a small map under the text. You can see it in action by clicking the screenshot below.
All you need to do to use the script is get your own Google Maps key and embed the script in the page you want to analyse, giving it the ID of the main text element as a parameter:
You can customise the look and feel by writing your own CSS for the generated HTML and setting the addmap.config.width
and addmap.config.height
properties to resize the map.
Under the hood here is what happens:
- The script grabs the innerHTML of the element and runs it through the open YQL table of Yahoo Placemaker.
- It then takes the data, assembles the HTML and puts together the URI for the map
- The map gets displayed using the Google static map API
The code of addmap.js is available on GitHub.
Tags: geo, googlemaps, javascript, maps, placemaker, yql