﻿<?xml version="1.0" encoding="utf-8" ?>
<ignite version="1.0" source="google">

  <!-- https://developers.google.com/maps/documentation/geocoding/ -->
  <!-- http://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=true -->
  <func name="geocode" endpoint="http://maps.googleapis.com/maps/api/geocode/xml?" method="GET" format="XML">
    <description>
      This function takes an address as input, searches the Google map, and returns formatted_address, latitude, longitude or location_type for the first matching result.
    </description>
    <example>
      =Ignite("google","geocode","formatted_address", "white house")
    </example>
    <document>
      <![CDATA[
      <a class="doc" href="https://developers.google.com/maps/documentation/geocoding/">Documentation</a>
]]>
    </document>
    <inputs>
      <input name="address" type ="input1"/>
      <input name="sensor"  type="config" value ="false"/>
      <input name="auth_token" type="config" value=""/>
    </inputs>
    <outputs>
      <output name="formatted_address" path="//result[1]/formatted_address"/>
      <output name="latitude" path="//result[1]/geometry/location/lat"/>
      <output name="longitude" path="//result[1]/geometry/location/lng"/>
      <output name="location_type" path="//result[1]/geometry/location_type"/>
    </outputs>
    <status ERROR_path="//status[. != 'OK']" OK_path="//status[. = 'OK']" />
  </func>

  <!--func name="geocode2" endpoint="http://maps.googleapis.com/maps/api/geocode/json?" method="GET" format="JSON" >
    <description>
      This function takes an address as input, seaches the goole map,
      and returns formatted_address, latitude, longitude or location_type for the first matching result.
    </description>
    <inputs>
      <input name="address" type ="input1"/>
      <input name="sensor"  type="config" value ="false"/>
      <input name="auth_token" type="config" value=""/>
    </inputs>
    <outputs>
      <output name="formatted_address" path="results[0].formatted_address"/>
      <output name="latitude" path="results[0].geometry.location.lat"/>
      <output name="longitude" path="results[0].geometry.location.lng"/>
      <output name="location_type" path="results[0].geometry.location.location_type"/>
    </outputs>
  </func-->

  <examples>
    <![CDATA[

<table border='1' class='ExcelTable2007'>
<tr><th class='heading'>&nbsp;</th><th>A</th><th>B (Forumla)</th><th>C (Output) </th></tr>
<tr><td class='heading' >1</td>
    <td>white house</td>
    <td>=Ignite("google","geocode","formatted_address", A1)</td>
    <td>The White House, President's Park, 1600 Pennsylvania Ave NW, Washington, DC 20500, USA</td>
</tr>
<tr><td class='heading' >2</td>
    <td>1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA</td>
    <td>=Ignite("google","geocode","latitude",A2)</td>
    <td>37.4221913</td>
</tr>
<tr><td class='heading' >3</td>
    <td>1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA</td>
    <td>=Ignite("google","geocode","longitude", A3)</td>
    <td>-122.0845853</td>
</tr>
<tr><td class='heading' >4</td>
    <td>1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA</td>
    <td>=Ignite("google","geocode","location_type", A4)</td>
    <td>ROOFTOP</td>
</tr>
</table>
      ]]>
  </examples>
  
</ignite>
