Posted 09/29/2008 - 22:56 by igo
Have you ever wanted to translate zip codes to Lat/Long to display in Google Maps? Here's the example to do it! [Don’t forget that this code requires a REST service in Presto named "geonames": http://ws.geonames.org/postalCodeSearch?postalcode=06700&country=MX.]
<mashup xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemalocation="http://www.jackbe.com/2008-03-01/EMMLSchema ../src/schemas/EMMLSpec.xsd"
xmlns="http://www.jackbe.com/2008-03-01/EMMLSchema" xmlns:macro="http://www.jackbe.com/2008-03-01/EMMLMacro"
name="zip2lat">
<operation
name="invoke"> <!-- Here are our variables. Zipcode and Country are the variables in our REST. They have default variables to avoid sending it empty and receive an unexpected result -->
<input name="zipcode" type="string" default="06700" />
<input name="country" type="string" default="MX" />
<output name="result" type="document"></output>
<!-- We will be saving the lat/lng in these variables to have them in our constructor. Perhaps just a way to keep things organized since for later usage it could become a huge code if not modularized -->
<variables>
<variable name="lat" type="string"></variable>
<variable name="lng" type="string"></variable>
</variables>
<!-- Here we invoke the REST we published in service explorer and send the previous inputs to it -->
<invoke operation="getData" service="geonames" inputvariables="zipcode,country"
outputvariable="preliminary"></invoke>
<assign fromexpr="$preliminary//lat/string()" outputvariable="lat"></assign>
<assign fromexpr="$preliminary//lng/string()" outputvariable="lng"></assign>
<!-- Building the output -->
<constructor outputvariable="result" />
</operation>
</mashup>
(1 vote)
- Login or register to post comments
- Email this page
