I'd simply decode the plus codes into lat/longs and then calculate the
distance between the center point and all points, sort by that distance,
and cut off. As Andreas points out, you need to worry about latitude: the
distance from (a, b) to (c, d) is roughly sqrt((|a-c|*111.12)^2 +
(|b-d|*cos((a-c)/2)*111.12)^2) if you (a,b) and (c,d) are close enough. If
not, you can use a library such as S2 <http://s2geometry.io/> to do the
calculations on a sphere/geoid.

On Tue, Mar 26, 2019 at 6:53 PM Andreas B <andr...@bocops.de> wrote:

> Hi Sidd,
>
> assuming that you have full, 10-digit codes for all locations (both stored
> and the user location), you can generate "neighboring" code areas and
> compare string prefixes as necessary. An example:
>
> 1. Assume that your user's location is *CFGHJMPQ+RV*. At ten digits, this
> corresponds to an area of at most 14m by 14m. This means that every other
> location starting with the same 10-digit code is within a couple of meters
> of your user's location.
>
> 2. This might be too precise for your application, so you could just cut
> two digits from your code. Every other location starting with *CFGHJMPQ *is
> located inside the same 275m by 275m area, meaning that is is at most ~390m
> away (diagonal of this area).
>
> 3. Cutting another two digits, every other location starting with *CFGHJM* is
> located inside the same 5.5km by 5.5km area, at most ~7.7km away.
>
> 4. Then, considering the eight adjacent six-digit codes: *CFGH[J+/-1][M+/-1]
> *gives you an area of three times that width and height, very roughly
> centered around your user's position. This should include all locations
> that are less than 5.5km away, but may include some locations up two 15km
> (two times the diagonal) away. These would need to be filtered in a second
> step, but for a short list of potential candidates this wouldn't be too
> hard.
>
> One thing that is important to consider is that the above values for the
> area size are only correct at the equator. The areas shrink in width
> towards the poles, which you would need to take into account by considering
> more neighbors if necessary.
>
> A while ago, I wrote a Java class wrapping OpenLocationCode objects that
> does some of this. There haven't been many updates in the last year or so,
> but it does the trick for some of my very similar use cases. Perhaps you
> can get an idea here: https://github.com/bocops/open-geotiling
>
>
>
> On Tuesday, March 26, 2019 at 10:11:11 AM UTC+1, sidd...@gmail.com wrote:
>>
>> Hi,
>>
>> I think I am looking at a similar scenario and so, reviving this older
>> thread. Excuse me if unrelated.
>>
>> I have a bunch of plus codes (places within a city). I want to be able to
>> find a subset of plus codes that fall within a radius of 'x' kms from
>> another given plus code (current location of a user). Eg. get all bus
>> stations within 5 kms of the current location of the user, where the plus
>> codes of the bus stations are stored by my application.
>>
>> Conceptually I think I should be able to determine similarity between
>> plus codes and perhaps compute distances from this subset to the current
>> user location.
>>
>> Wanted the group's suggestion on how I may be able to accomplish this?
>>
>> Cheers,
>> Sidd
>>
>>>
>>> --
> Public site: http://www.openlocationcode.com/
> Github project: https://github.com/google/open-location-code
> Demo site: http://plus.codes/
> ---
> You received this message because you are subscribed to the Google Groups
> "Plus Codes Community Forum" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to open-location-code+unsubscr...@googlegroups.com.
> To post to this group, send email to open-location-code@googlegroups.com.
> Visit this group at https://groups.google.com/group/open-location-code.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/open-location-code/f783fbe0-e460-43a4-9d17-98418aa64ba2%40googlegroups.com
> <https://groups.google.com/d/msgid/open-location-code/f783fbe0-e460-43a4-9d17-98418aa64ba2%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
Public site: http://www.openlocationcode.com/
Github project: https://github.com/google/open-location-code
Demo site: http://plus.codes/
--- 
You received this message because you are subscribed to the Google Groups "Plus 
Codes Community Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to open-location-code+unsubscr...@googlegroups.com.
To post to this group, send an email to open-location-code@googlegroups.com.
Visit this group at https://groups.google.com/group/open-location-code.
To view this discussion on the web, visit 
https://groups.google.com/d/msgid/open-location-code/CALCXoY2kiTMbs%2B5eixqUDdtU64qJvYCG%3DcRQYsvgaHD3N%3D8kRA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to