blob: bb66dc2318aafc095bb39c13aca8f12daf18052c [file] [log] [blame]
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Geolocating your Entities &mdash; Apache Usergrid 1.0 documentation</title>
<link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
<link rel="top" title="Apache Usergrid 1.0 documentation" href="../index.html"/>
<link rel="next" title="Uploading assets" href="../assets-and-files/uploading-assets.html"/>
<link rel="prev" title="App Example - Messagee" href="../user-management/messagee-example.html"/>
<script src="../_static/js/modernizr.min.js"></script>
</head>
<body class="wy-body-for-nav" role="document">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-nav-search">
<a href="../index.html" class="icon icon-home"> Apache Usergrid
</a>
<div class="version">
1.0
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<p class="caption"><span class="caption-text">Getting Started</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../introduction/overview.html">Getting Started</a></li>
<li class="toctree-l1"><a class="reference internal" href="../introduction/usergrid-features.html">Usergrid Features</a></li>
<li class="toctree-l1"><a class="reference internal" href="../introduction/data-model.html">Usergrid Data model</a></li>
<li class="toctree-l1"><a class="reference internal" href="../introduction/async-vs-sync.html">Async vs. sync calls</a></li>
</ul>
<p class="caption"><span class="caption-text">Using Usergrid</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../using-usergrid/creating-account.html">Creating a Usergrid Account</a></li>
<li class="toctree-l1"><a class="reference internal" href="../using-usergrid/creating-a-new-application.html">Creating a new application</a></li>
<li class="toctree-l1"><a class="reference internal" href="../using-usergrid/using-a-sandbox-app.html">Using a Sandbox Application</a></li>
<li class="toctree-l1"><a class="reference internal" href="../using-usergrid/using-the-api.html">Using the API</a></li>
</ul>
<p class="caption"><span class="caption-text">Data Storage</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../data-storage/data-store-dbms.html">The Usergrid Data Store</a></li>
<li class="toctree-l1"><a class="reference internal" href="../data-storage/optimizing-access.html">Data Store Best Practices</a></li>
<li class="toctree-l1"><a class="reference internal" href="../data-storage/collections.html">Collections</a></li>
<li class="toctree-l1"><a class="reference internal" href="../data-storage/entities.html">Entities</a></li>
</ul>
<p class="caption"><span class="caption-text">Data Queries</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../data-queries/querying-your-data.html">Querying your data</a></li>
<li class="toctree-l1"><a class="reference internal" href="../data-queries/query-parameters.html">Query parameters &amp; clauses</a></li>
<li class="toctree-l1"><a class="reference internal" href="../data-queries/operators-and-types.html">Query operators &amp; data types</a></li>
<li class="toctree-l1"><a class="reference internal" href="../data-queries/advanced-query-usage.html">Advanced query usage</a></li>
</ul>
<p class="caption"><span class="caption-text">Entity Connections</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../entity-connections/connecting-entities.html">Connecting entities</a></li>
<li class="toctree-l1"><a class="reference internal" href="../entity-connections/retrieving-entities.html">Retrieving connections</a></li>
<li class="toctree-l1"><a class="reference internal" href="../entity-connections/disconnecting-entities.html">Disconnecting entities</a></li>
</ul>
<p class="caption"><span class="caption-text">Push Notifications</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../push-notifications/overview.html">Push notifications overview</a></li>
<li class="toctree-l1"><a class="reference internal" href="../push-notifications/adding-push-support.html">Adding push notifications support</a></li>
<li class="toctree-l1"><a class="reference internal" href="../push-notifications/getting-started.html">Getting started with push notifications</a></li>
<li class="toctree-l1"><a class="reference internal" href="../push-notifications/tutorial.html">Tutorial: Push notifications sample app</a></li>
<li class="toctree-l1"><a class="reference internal" href="../push-notifications/registering.html">Registering with a notification service</a></li>
<li class="toctree-l1"><a class="reference internal" href="../push-notifications/creating-notifiers.html">Creating notifiers</a></li>
<li class="toctree-l1"><a class="reference internal" href="../push-notifications/managing-users-and-devices.html">Managing users and devices</a></li>
<li class="toctree-l1"><a class="reference internal" href="../push-notifications/creating-and-managing-notifications.html">Creating and managing notifications</a></li>
<li class="toctree-l1"><a class="reference internal" href="../push-notifications/troubleshooting.html">Troubleshooting</a></li>
</ul>
<p class="caption"><span class="caption-text">Security &amp; Authentication</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../security-and-auth/app-security.html">Security &amp; token authentication</a></li>
<li class="toctree-l1"><a class="reference internal" href="../security-and-auth/using-permissions.html">Using permissions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../security-and-auth/using-roles.html">Using roles</a></li>
<li class="toctree-l1"><a class="reference internal" href="../security-and-auth/authenticating-users-and-application-clients.html">Authenticating users &amp; app clients</a></li>
<li class="toctree-l1"><a class="reference internal" href="../security-and-auth/user-authentication-types.html">Authentication levels</a></li>
<li class="toctree-l1"><a class="reference internal" href="../security-and-auth/changing-token-time-live-ttl.html">Changing token expiration (time-to-live)</a></li>
<li class="toctree-l1"><a class="reference internal" href="../security-and-auth/authenticating-api-requests.html">Authenticating API requests</a></li>
<li class="toctree-l1"><a class="reference internal" href="../security-and-auth/revoking-tokens-logout.html">Revoking tokens (logout)</a></li>
<li class="toctree-l1"><a class="reference internal" href="../security-and-auth/facebook-sign.html">Facebook sign in</a></li>
<li class="toctree-l1"><a class="reference internal" href="../security-and-auth/securing-your-app.html">Security best practices</a></li>
</ul>
<p class="caption"><span class="caption-text">User Management &amp; Social Graph</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../user-management/user-management.html">User management &amp; social graph</a></li>
<li class="toctree-l1"><a class="reference internal" href="../user-management/working-user-data.html">Working with User Data</a></li>
<li class="toctree-l1"><a class="reference internal" href="../user-management/group.html">Working with group data</a></li>
<li class="toctree-l1"><a class="reference internal" href="../user-management/activity.html">Activity</a></li>
<li class="toctree-l1"><a class="reference internal" href="../user-management/user-connections.html">Social Graph Connections</a></li>
<li class="toctree-l1"><a class="reference internal" href="../user-management/user-connections.html#creating-other-connections">Creating other connections</a></li>
<li class="toctree-l1"><a class="reference internal" href="../user-management/messagee-example.html">App Example - Messagee</a></li>
</ul>
<p class="caption"><span class="caption-text">Geo-location</span></p>
<ul class="current">
<li class="toctree-l1 current"><a class="current reference internal" href="">Geolocating your Entities</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#saving-location-data-in-an-entity">Saving location data in an entity</a></li>
<li class="toctree-l2"><a class="reference internal" href="#querying-location-data">Querying location data</a></li>
<li class="toctree-l2"><a class="reference internal" href="#enrich-your-app-with-location-data">Enrich your app with location data</a></li>
</ul>
</li>
</ul>
<p class="caption"><span class="caption-text">Assets &amp; Files</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../assets-and-files/uploading-assets.html">Uploading assets</a></li>
<li class="toctree-l1"><a class="reference internal" href="../assets-and-files/retrieving-assets.html">Retrieving assets</a></li>
<li class="toctree-l1"><a class="reference internal" href="../assets-and-files/folders.html">Folders</a></li>
</ul>
<p class="caption"><span class="caption-text">Counters &amp; Events</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../counters-and-events/events-and-counters.html">Counters &amp; events</a></li>
<li class="toctree-l1"><a class="reference internal" href="../counters-and-events/creating-and-incrementing-counters.html">Creating &amp; incrementing counters</a></li>
<li class="toctree-l1"><a class="reference internal" href="../counters-and-events/creating-and-incrementing-counters.html#decrementing-resetting-counters">Decrementing/resetting counters</a></li>
<li class="toctree-l1"><a class="reference internal" href="../counters-and-events/creating-and-incrementing-counters.html#using-counters-hierarchically">Using counters hierarchically</a></li>
<li class="toctree-l1"><a class="reference internal" href="../counters-and-events/retrieving-counters.html">Retrieving counters</a></li>
</ul>
<p class="caption"><span class="caption-text">Organizations &amp; Applications</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../orgs-and-apps/managing.html">Organization &amp; application management</a></li>
<li class="toctree-l1"><a class="reference internal" href="../orgs-and-apps/organization.html">Organization</a></li>
<li class="toctree-l1"><a class="reference internal" href="../orgs-and-apps/application.html">Application</a></li>
<li class="toctree-l1"><a class="reference internal" href="../orgs-and-apps/admin-user.html">Admin user</a></li>
</ul>
<p class="caption"><span class="caption-text">API Reference</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../rest-endpoints/api-docs.html">Methods</a></li>
<li class="toctree-l1"><a class="reference internal" href="../rest-endpoints/api-docs.html#models">Models</a></li>
<li class="toctree-l1"><a class="reference internal" href="../rest-endpoints/api-docs.html#sub-types">Sub-Types</a></li>
</ul>
<p class="caption"><span class="caption-text">Client SDKs</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../sdks/tbd.html">COMING SOON...</a></li>
</ul>
<p class="caption"><span class="caption-text">Installing Usergrid</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../installation/deployment-guide.html">Usergrid 2.1.0 Deployment Guide</a></li>
</ul>
<p class="caption"><span class="caption-text">More about Usergrid</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../reference/presos-and-videos.html">Presentations &amp; Videos</a></li>
<li class="toctree-l1"><a class="reference internal" href="../reference/contribute-code.html">How to Contribute Code &amp; Docs</a></li>
</ul>
</div>
&nbsp;
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" role="navigation" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../index.html">Apache Usergrid</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../index.html">Docs</a> &raquo;</li>
<li>Geolocating your Entities</li>
<li class="wy-breadcrumbs-aside">
<a href="../_sources/geolocation/geolocation.txt" rel="nofollow"> View page source</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<div class="section" id="geolocating-your-entities">
<h1>Geolocating your Entities<a class="headerlink" href="#geolocating-your-entities" title="Permalink to this headline"></a></h1>
<p>Many of today&#8217;s apps are enhanced by the use of geolocation – wireless
detection of the physical location of a remote device. These apps
determine the user&#8217;s position and use this data to enhance user
experience. For example, apps can capture the exact location where a
picture was taken or determine what businesses stored in the database to
return to the user based on their current location.</p>
<p>API Services provides a standard format for storing geolocation
information in any entity, as well as syntax for querying that data
based on distance from a latitude/longitude point.</p>
<div class="section" id="saving-location-data-in-an-entity">
<h2>Saving location data in an entity<a class="headerlink" href="#saving-location-data-in-an-entity" title="Permalink to this headline"></a></h2>
<p>In API Services, geolocation data is saved in the location property of
an entity with latitude and longitude sub-properites in the following
format:</p>
<div class="highlight-python"><div class="highlight"><pre>&quot;location&quot;: {
&quot;latitude&quot;: &lt;latitude_coordinate&gt;,
&quot;longitude&quot;: &lt;longitude_coordinate&gt;
}
</pre></div>
</div>
<p>An entity&#8217;s geolocation can be specified when the entity is
<a class="reference external" href="../data-storage/entities.html#creating-custom-data-entities">created</a>
or added later by
<a class="reference external" href="../data-storage/entities.html#updating-data-entities">updating</a> an
existing entity.</p>
<p>For example, the following entity describes a restaurant:</p>
<div class="highlight-python"><div class="highlight"><pre>{
&quot;uuid&quot; : &quot;03ae956a-249f-11e3-9f80-d16344f5a0e1&quot;,
&quot;type&quot; : &quot;restaurant&quot;,
&quot;name&quot; : &quot;Rockadero&quot;,
&quot;location&quot;: {
&quot;latitude&quot;: 37.779632,
&quot;longitude&quot;: -122.395131
}
&quot;created&quot; : 1379975113142,
&quot;modified&quot; : 1379975113142,
&quot;metadata&quot; : {
&quot;path&quot; : &quot;/restaurants/03ae956a-249f-11e3-9f80-d16344f5a0e1&quot;
}
</pre></div>
</div>
</div>
<div class="section" id="querying-location-data">
<h2>Querying location data<a class="headerlink" href="#querying-location-data" title="Permalink to this headline"></a></h2>
<p>Location-aware apps require the ability to return content and results
based on the user&#8217;s current location. To easily enable this, API
Services supports the following query parameter to retrieve entities
within a specified distance of any geocoordinate based on its location
property:</p>
<div class="highlight-python"><div class="highlight"><pre>location within &lt;distance_in_meters&gt; of &lt;latitude&gt;, &lt;longitude&gt;
</pre></div>
</div>
<p>The returned results are sorted from nearest to furthest. Entities with
the same location are returned in the order they were created.</p>
<p>The location parameter can be appended to any standard API Services
query. For more information on how to query your API Services data, see
<a class="reference external" href="../data-queries/querying-your-data.html">Querying your Data</a>.</p>
<p>For example, here is how you would find all the devices within 8,046
meters (~10 miles) of the center of San Francisco:</p>
<div class="highlight-python"><div class="highlight"><pre>curl -X GET https://api.usergrid.com/your-org/your-app/devices?ql=location within 8046 of 37.774989,-122.419413
</pre></div>
</div>
</div>
<div class="section" id="enrich-your-app-with-location-data">
<h2>Enrich your app with location data<a class="headerlink" href="#enrich-your-app-with-location-data" title="Permalink to this headline"></a></h2>
<p>Location-awareness has become a feature users expect in many types of
mobile applications because of its ability to create a more personalized
and relevant experience for each user. With this in mind, the
geolocation feature in API Services was designed to work with many of
the available <a class="reference external" href="../api-docs.html#models">default data entities</a> to
allow app developers to easily integrate powerful in-app features that
can increase user engagement.</p>
<p>Here are just a few of the ways that saving location data to a data
entity can improve an app:</p>
<table class="usergrid-table">
<tr>
<th><p>Entity</p>
</th>
<th><p>Usage</p>
</th>
</tr>
<tr>
<td><p>user</p>
</td>
<td><p>Save the location of a user&#8217;s home as part of their profile in the
<code class="docutils literal"><span class="pre">users</span></code> collection to suggest upcoming special events or activities
located nearby, or to display advertisements that are relevant based on
the user&#8217;s proximity to a business.</p>
</td>
</tr>
<tr>
<td><p>device</p>
</td>
<td><p>Periodically save the location data returned from a user&#8217;s device, then
query the <code class="docutils literal"><span class="pre">devices</span></code> collection to send offers and alerts to user&#8217;s
that are located near your business with a <a class="reference external" href="../push-notifications/push-notifications-overview">push
notification</a>.</p>
</td>
</tr>
<tr>
<td><p>activity</p>
</td>
<td><p>Create stronger social connections by associating a user <code class="docutils literal"><span class="pre">activity</span></code>
with the location where it occurred. The activity can then be displayed
to nearby friends and family, or used to enrich the user&#8217;s activity
stream.</p>
</td>
</tr>
<tr>
<td><p>asset</p>
</td>
<td><p>Save user photos with location data in the <code class="docutils literal"><span class="pre">asset</span> <span class="pre">collection</span></code> to allow
users to retrieve and sort their memories based on when and where they
happened.</p>
</td>
</tr>
</table></div>
</div>
</div>
</div>
<footer>
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
<a href="../assets-and-files/uploading-assets.html" class="btn btn-neutral float-right" title="Uploading assets" accesskey="n">Next <span class="fa fa-arrow-circle-right"></span></a>
<a href="../user-management/messagee-example.html" class="btn btn-neutral" title="App Example - Messagee" accesskey="p"><span class="fa fa-arrow-circle-left"></span> Previous</a>
</div>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2013-2015, Apache Usergrid.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT:'../',
VERSION:'1.0',
COLLAPSE_INDEX:false,
FILE_SUFFIX:'.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<script type="text/javascript" src="../_static/js/theme.js"></script>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.StickyNav.enable();
});
</script>
</body>
</html>