<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE xep SYSTEM 'xep.dtd' [
  <!ENTITY % ents SYSTEM 'xep.ent'>
%ents;
]>
<?xml-stylesheet type='text/xsl' href='xep.xsl'?>
<xep>
  <header>
    <title>Data Forms Geolocation Element</title>
    <abstract>This specification defines an XMPP protocol extension for including geolocation data in XEP-0004 data forms.</abstract>
    &LEGALNOTICE;
    <number>0350</number>
    <status>Experimental</status>
    <type>Standards Track</type>
    <sig>Standards</sig>
    <dependencies>
      <spec>XMPP Core</spec>
      <spec>XEP-0004</spec>
      <spec>XEP-0080</spec>
      <spec>XEP-0122</spec>
    </dependencies>
    <supersedes/>
    <supersededby/>
    <shortname>geolocation-element</shortname>
    <schemaloc>
      <url>http://www.xmpp.org/schemas/geolocation-element.xsd</url>
    </schemaloc>
    <author>
      <firstname>Michael</firstname>
      <surname>Laukner</surname>
      <email>laukner@gmail.com</email>
      <jid>laukner@jabber.org</jid>
    </author>
    <revision>
      <version>0.1</version>
      <date>2014-07-03</date>
      <initials>editor (mam)</initials>
      <remark>
        <p>Initial published version approved by the XMPP Council.</p>
      </remark>
    </revision>
    <revision>
      <version>0.0.3</version>
      <date>2014-06-28</date>
      <initials>ml</initials>
      <remark>
        <p>Updated version, added 'geo:' datatypes to support 'text-single' use case.</p>
      </remark>
    </revision>
    <revision>
      <version>0.0.2</version>
      <date>2014-06-25</date>
      <initials>ml</initials>
      <remark>
        <p>Updated version, added XEP-0122 'geo:' datatypes.</p>
      </remark>
    </revision>
    <revision>
      <version>0.0.1</version>
      <date>2014-06-11</date>
      <initials>ml</initials>
      <remark>
        <p>Initial version, borrowing from XEP-0221.</p>
      </remark>
    </revision>
  </header>
  <section1 topic='Introduction' anchor='intro'>
    <p>In certain protocols that make use of &xep0004;, it can be helpful to include geolocation data. One example of such a "using protocol" is &xep0346;. This document defines a method for including geolocation data in a <cite>Data Form</cite> for something you manage and want to publish. This XEP leaves it open to developers how such a &lt;geoloc/&gt; form element will be rendered; possibilities might include editing Latitude and Longitude manually or through a rendered map.</p>
    <p>There may also be the need to gather location data from both humans (using a GUI format) and computer processes (using a pre-defined but flexible format). This document defines a flexible mechanism for the &REGISTRAR; to standardize geographical location field names in data forms, thus enabling XMPP clients to process location fields in forms while giving protocol authors a way to specify additional location data types for non-GUI processors to determine the semantic meanings of a location field.</p>
  </section1>
  <section1 topic='Requirements' anchor='requirements'>
    <p>This proposal addresses the following requirements:</p>
     <ul>
       <li>Integrate geolocation data with XEP-0004.</li>
       <li>Allow a potential receiver (rather than the sender) to validate geolocation data.</li>
    </ul>
  </section1>
  <section1 topic='Integrate Geolocation Element with XEP-0004' anchor='geolocation'>
    <p>The root element for geolocation data is &lt;geoloc/&gt; as defined in &xep0080;. The information is structured by means of a &lt;geoloc/&gt; element that is qualified by the 'http://jabber.org/protocol/geoloc' namespace. The &lt;geo/&gt; element MUST be contained within a &lt;field/&gt; element qualified by the 'jabber:x:data' namespace.</p>
    <p>The following example is provided only for the purpose of illustration; consult the specifications for using protocols (e.g., XEP-0080) to see canonical examples.</p>
    <example caption='Inclusion in Data Form'><![CDATA[<x xmlns='jabber:x:data' type='form'>
  [ ... ]
   <field var='location'>
     <geoloc xmlns="http://jabber.org/protocol/geoloc">
        <text>Venice, Italy</text>
        <locality>Venice</locality>
        <country>Italy</country>
        <lat>45.44</lat>
        <lon>12.33</lon>
     </geoloc>
   </field>
   [ ... ]
</x>]]></example>
  </section1>
  <section1 topic='Allow Receiver to Valdidate Geolocation Data' anchor='validation'>
    <p>All elements associated with location fields MUST be qualified by the 'http://jabber.org/protocol/geoloc' namespace. The use of namespace prefixes is RECOMMENDED for large forms, to reduce the data size. To maintain the highest level of compatibility, implementations sending the form using prefixes SHOULD use the namespace prefix "geo:", and SHOULD declare the namespace prefix mapping in the ancestor &lt;x xmlns='jabber:x:data'/&gt; element:</p>
    <p>The following example is provided only for the purpose of illustration; consult the specifications for using protocols (e.g. XEP-0080, XEP-0122) to see canonical examples.</p>
    <example caption='Validation of Geolocation Data'><![CDATA[<x xmlns='jabber:x:data' 
   xmlns:geo= http://jabber.org/protocol/geoloc'
   xmlns:xdv='http://jabber.org/protocols/xdata-validate'
   type='form'>
  <title>Sample Location Form</title>
  <instructions>
    Please provide information for the following location fields...
  </instructions>
  <field type='text-single' var='name' label='Event Name'/>
  <field type='text-single' var='time' label='Event Date/Time'>
    <xdv:validate datatype='xs:dateTime'>
      <basic/>
    </xdv:validate>
  </field>
  <field type='text-single' var='latitude' label='Latitude'>
    <xdv:validate datatype='geo:lat'>
      <basic/>
    </xdv:validate>
  </field>
  <field type='text-single' var='longitude' label='Longitude'>
    <xdv:validate datatype='geo:lon'>
      <basic/>
    </xdv:validate>
  </field>
</x>]]></example>
    <section2 topic='Location Datatypes for Data Forms' anchor='location_fields'>
    <p>The integration with Data Forms is accomplished via the datatypes specified in &xep0122;. Each datatype is specific to the profile desired. The sender MUST use the 'geo:' datatypes as specified in XEP-0122. When submitting a form, a field's value(s) MUST be validated by the receiving entity based on the 'geo:' datatype identifier(s). Also, the submitter MUST provide a 'geo:' element for each location element within the data form. If a form-submitting entity receives a field type it does not understand, the 'text-single' field type from XEP-0004 MUST be assumed.</p>
    </section2>
  </section1>
  <section1 topic='Security Considerations' anchor='security'>
    <p>It is imperative to control access to location information, at least by default. Imagine that a stalker got unauthorized access to this information, with enough accuracy and timeliness to be able to find the target person. This scenario could lead to loss of life, so please take access control checks seriously. If an error is deliberately added to a location, the error SHOULD be the same for all receivers, to minimize the likelihood of triangulation. In the case of deliberate error, the &lt;accuracy /> element SHOULD NOT be included.</p>
  </section1>
  <section1 topic='IANA Considerations' anchor='iana'>
    <p>This document requires no interaction with the &IANA;.</p>
  </section1>
  <section1 topic='XMPP Registrar Considerations' anchor='registrar'>
    <section2 topic='Protocol Namespaces' anchor='ns'>
      <p>
        The &REGISTRAR; already includes 'http://jabber.org/protocol/geoloc' in its registry of protocol namespaces (see &NAMESPACES;).
      </p>
    </section2>
    <section2 topic='Location Fields and Data Form Validation Datatypes' anchor='registrar.geo.xep'>
      <p>The XMPP Registrar includes 'geo:' in its registry of Data Forms Validation Datatype Prefixes.</p>
      <p>Normally, each geographic format that wishes to be considered for use with Data Forms MUST register its own datatype qualified by the "geo:" prefix. However, this document provides an initial seed, based on the currently assumed formats. The following datatypes shall be registered for use with Data Forms Validation:</p>
      <code caption='Latitude Validation Datatype Registry Submission'><![CDATA[
<datatype>
  <name>geo:lat</name>
  <desc>Datatype for publishing the latitude of a geographic location</desc>
  <doc>XEP-0080</doc>
</datatype>
]]></code>
<example caption='Validation of a XEP-0080 Latitude Field'><![CDATA[
<field type='text-single' var='latitude' label='Latitude'>
  <xdv:validate datatype='geo:lat'>
    <range min='-90' 
           max='90'/>
  </xdv:validate>
  <value>45.44</value>
</field>]]></example>

      <code caption='Longitude Validation Datatype Registry Submission'><![CDATA[
<datatype>
  <name>geo:lon</name>
  <desc>Datatype for publishing the longitude of a geographic location</desc>
  <doc>XEP-0080</doc>
</datatype>
]]></code>
<example caption='Validation of XEP-0080 Longitude Field'><![CDATA[
<field type='text-single' var='longitude' label='Longitude'>
  <xdv:validate datatype='geo:lon'>
    <range min='-180' 
         max='180'/>
  </xdv:validate>
  <value>12.33</value>
</field>]]></example>
    </section2>
 
    <section2 topic='Text Field and Data Form Validation Datatypes' anchor='registrar.geo.text'>
      <p>The XMPP Registrar MAY include 'geo:' datatypes in its registry of Data Forms Validation Datatypes, which can be used with the 'text-single' field type from XEP-0004.</p>
  
    <code caption='DMS Data Forms Validation Datatype Registry Submission'><![CDATA[
<datatype>
  <name>geo:dms</name>
  <desc>Datatype for publishing a degrees, minutes, and seconds (DMS) location</desc>
  <doc>Degree Minutes and Seconds, 'http://en.wikipedia.org/wiki/Geographic_coordinate_system'.</doc>
</datatype>
]]></code>
<example caption='Validation of a DMS Location Field'><![CDATA[
<field type='text-single' var='dms_location'>
  <xdv:validate datatype='geo:dms'/>
    <regex>([-|\\+]?\\d{1,3}[d|D|\u00B0|\\s](\\s*\\d{1,2}['|\u2019|\\s])?(\\s*\\d{1,2}[\"|\u201d])?\\s*[N|n|S|s]?)?(\\s*|,|,\\s*)?([-|\\+]?\\d+?(\\.\\d+?)??\\s*[E|e|W|w]??)</regex>
  </xdv:validate>
  <value>52d18'24.4775"N 0d52'44.0625"W</value>
</field>]]></example>
 
    <code caption='MGRS Data Forms Validation Datatype Registry Submission'><![CDATA[
<datatype>
  <name>geo:mgrs</name>
  <desc>Datatype for publishing a MGRS location</desc>
  <doc>Military Grid Reference System, 'http://en.wikipedia.org/wiki/Military_grid_reference_system'.</doc>  
</datatype>
]]></code>
<example caption='Validation of a MGRS Location Field'><![CDATA[
<field type='text-single' var='mgrs_location'>
  <xdv:validate datatype='geo:mgrs'/>
    <regex>\\d{1,2}[A-Za-z]\\s*[A-Za-z]{2}\\s*\\d{1,5}\\s*\\d{1,5}</regex>
  </xdv:validate>
  <value>38SMB4484</value>
</field>]]></example>
 
  </section2>
  </section1>
  <section1 topic='XML Schema' anchor='schema'>
    <p>As this document only defines semantics for existing protocol, additional schemas are not required.</p>
  </section1>
</xep>
