Sample javascript for calling out to Yahoo! maps

Yahoo! Maps provides a set of web services APIs for external applications to use Yahoo! Maps as a service. The simplest API allows you to place a location on a map by calling a simple HTTP POST method. Basically, the body of the POST (e.g. the data sent along with your HTTP request) contains an XML file that describes what to place on the map. Here, we provide a snippet of javascript that you can embed in an HTML page or rails view to call this HTTP POST method.

First, obtain a Yahoo! App ID. Second, cut and paste this code into your HTML file or rails view (this code should work in Firefox and IE). You will need to edit the javascript where it says "YOUR_APP_ID_HERE" and replace that with the Yahoo! App ID you obtained. Third, you can call this javascript as follows:

<script type="text/javascript">
var cityName="Moscow";
var cityLat="55.7667";
var cityLong="37.6667";
</script>

<A HREF="javascript:doSubmit();">Get a map</A>
Of course, you'll need to substitute the appropriate city name, longitude and latitude in for the sample values above.

Now, when you point your browser at your HTML page or rails view, there should be a link labeled "Get a map"; clicking this button will take you to a map of your city.

Note that if the longitude and latitude are rounded off (e.g. 55.7 instead of 55.7667) the map may show a slightly wrong location; that is okay.