camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > Geocoder
Date Thu, 06 Jun 2013 05:10:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2042/9/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/CAMEL/Geocoder">Geocoder</a></h2>
    <h4>Page  <b>added</b> by             <a href="https://cwiki.apache.org/confluence/display/~davsclaus">Claus
Ibsen</a>
    </h4>
         <br/>
    <div class="notificationGreySide">
         <h2><a name="Geocoder-GeocoderComponent"></a>Geocoder Component</h2>
<p><b>Available as of Camel 2.12</b></p>

<p>The <b>geocoder:</b> component is used for looking up geocodes (latitude
and longitude) for a given address, or reverse lookup. The component uses the <a href="https://code.google.com/p/geocoder-java/"
class="external-link" rel="nofollow">Java API for Google Geocoder</a> library.</p>

<p>Maven users will need to add the following dependency to their <tt>pom.xml</tt>
for this component:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;dependency&gt;</span>
    <span class="code-tag">&lt;groupId&gt;</span>org.apache.camel<span
class="code-tag">&lt;/groupId&gt;</span>
    <span class="code-tag">&lt;artifactId&gt;</span>camel-geocoder<span
class="code-tag">&lt;/artifactId&gt;</span>
    <span class="code-tag">&lt;version&gt;</span>x.x.x<span class="code-tag">&lt;/version&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- use the same
version as your Camel core version --&gt;</span></span>
<span class="code-tag">&lt;/dependency&gt;</span>
</pre>
</div></div>

<h3><a name="Geocoder-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
geocoder:address:name[?options]
geocoder:latlng:latitude,longitude[?options]
</pre>
</div></div>

<h3><a name="Geocoder-Options"></a>Options</h3>

<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Property </th>
<th class='confluenceTh'> Default </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>language</tt> </td>
<td class='confluenceTd'> <tt>en</tt> </td>
<td class='confluenceTd'> The language to use. </td>
</tr>
</tbody></table>
</div>
</div>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<h3><a name="Geocoder-Exchangedataformat"></a>Exchange data format</h3>

<p>Camel will deliver the body as a <tt>com.google.code.geocoder.model.GeocodeResponse</tt>
type.</p>

<h3><a name="Geocoder-MessageHeaders"></a>Message Headers</h3>
<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Header </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelGeoCoderStatus</tt> </td>
<td class='confluenceTd'> Status code from the geocoder library. If status is <tt>GeocoderStatus.OK</tt>
then additional headers is enriched </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelGeoCoderAddress</tt> </td>
<td class='confluenceTd'> The formatted address </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelGeoCoderLatlng</tt> </td>
<td class='confluenceTd'> The latitude and longitude of the location. Separated by comma.
</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelGeoCoderCountryLong</tt> </td>
<td class='confluenceTd'> The country long name. May only be available in latlng mode.
</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelGeoCoderCountryShort</tt> </td>
<td class='confluenceTd'> The country short name. May only be available in latlng mode.
</td>
</tr>
</tbody></table>
</div>
</div>

<h3><a name="Geocoder-Samples"></a>Samples</h3>

<p>In the example below we get the latitude and longitude for Paris, France</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
  from(<span class="code-quote">"direct:start"</span>)
    .to(<span class="code-quote">"geocoder:address:Paris, France"</span>)
</pre>
</div></div>

<p>If you provide a header with the <tt>CamelGeoCoderAddress</tt> then that
overrides the endpoint configuration, so to get the location of Copenhagen, Denmark we can
send a message with a headers as shown:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
template.sendBodyAndHeader(<span class="code-quote">"direct:start"</span>, <span
class="code-quote">"Hello"</span>, GeoCoderConstants.ADDRESS, <span class="code-quote">"Copenhagen,
Denmark"</span>);
</pre>
</div></div>

<p>To get the address for a latitude and longitude we can do:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
  from(<span class="code-quote">"direct:start"</span>)
    .to(<span class="code-quote">"geocoder:latlng:40.714224,-73.961452"</span>)
    .log(<span class="code-quote">"Location ${header.CamelGeocoderAddress} is at lat/lng:
${header.CamelGeocoderLatlng} and in country ${header.CamelGeoCoderCountryShort}"</span>)
</pre>
</div></div>

<p>Which will log</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
Location 285 Bedford Avenue, Brooklyn, NY 11211, USA is at lat/lng: 40.71412890,-73.96140740
and in country US
</pre>
</div></div>
    </div>
    <div id="commentsSection" class="wiki-content pageSection">
       <div style="float: right;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
       </div>
       <a href="https://cwiki.apache.org/confluence/display/CAMEL/Geocoder">View Online</a>
              |
       <a href="https://cwiki.apache.org/confluence/display/CAMEL/Geocoder?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
           </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message