<p>How to work with geolocation-based features like geochats and the nearby users feature.</p>
<h3><aclass="anchor"href="#fetching-nearby-users-and-geogroups"id="fetching-nearby-users-and-geogroups"name="fetching-nearby-users-and-geogroups"><iclass="anchor-icon"></i></a>Fetching nearby users and geogroups</h3>
<p>Use <ahref="/method/contacts.getLocated">contacts.getLocated</a> to fetch a list of nearby users and groups. </p>
<p>Do <strong>not</strong> set any of the <code>background</code>, <code>self_expires</code> flags: only populate <code>geo_point</code> with the current geolocation of the user: a list of users and geochats located nearby will be returned (<strong>without</strong> publishing the current location of the user). </p>
<p>This functionality is useful for example to <ahref="/api/contacts#adding-telegram-users-as-contacts">exchange contacts</a> with a nearby Telegram user, or <ahref="/method/channels.joinChannel">join</a> a location-based group chat, see <ahref="https://telegram.org/blog/contacts-local-groups">here »</a> for more usecases. </p>
<p>See <ahref="#creating-a-geogroup">here »</a> for more info on how to create a geogroup, and <ahref="#advertising-our-current-location">here »</a> for more info on how to advertise our current location to other users. </p>
<h3><aclass="anchor"href="#creating-a-geogroup"id="creating-a-geogroup"name="creating-a-geogroup"><iclass="anchor-icon"></i></a>Creating a geogroup</h3>
<p>Pass a <code>geo_point</code> to <ahref="/method/channels.createChannel">channels.createChannel</a> when creating a <ahref="/api/channel">supergroup</a> in order to create a geogroup associated to a geolocation, that will be returned to <ahref="#fetching-nearby-users-and-geogroups">nearby users »</a>. </p>
<p>A textual description of the location (1-64 UTF-8 chars) should also be passed in <code>address</code>. </p>
<p>Use <ahref="/method/channels.editLocation">channels.editLocation</a> to change the group's location.</p>
<h3><aclass="anchor"href="#advertising-our-current-location"id="advertising-our-current-location"name="advertising-our-current-location"><iclass="anchor-icon"></i></a>Advertising our current location</h3>
<p>Our current location may be <ahref="#fetching-nearby-users-and-geogroups">advertised to other users</a> using <ahref="/method/contacts.getLocated">contacts.getLocated</a>: in this case the <code>self_expires</code> flag <strong>must always be set</strong>.</p>
<p>This flag is used to specify the expiration TTL of the passed geolocation (i.e. the geolocation will expire after <code>self_expires</code> seconds); pass <code>0x7fffffff</code> to disable expiry, 0 to make the current geolocation private. </p>
<p>The method will also return a list of nearby users and chats, but only if the passed expiration TTL is not equal to zero.<br>
Users may still fetch nearby users and chats without making their geolocation public by simply not setting the flag, see <ahref="#fetching-nearby-users-and-geogroups">here »</a> for more info. </p>
<p>While the geolocation of the current user is public, clients should update it in the background every half-an-hour or so (or in any case before the expiration date specified with <code>self_expires</code>), while setting this flag: if the new location is more than 1 KM away from the previous one, or if the previous location is unknown, the <code>background</code> flag should be set.</p></div>