Code Monkey home page Code Monkey logo

Comments (2)

davidmoten avatar davidmoten commented on August 19, 2024

This is how I fixed this issue in java code:

 public static String adjacentHash(String hash, Direction direction) {
        checkHash(hash);
        Preconditions
                .checkArgument(hash.length() > 0,
                        "adjacent has no meaning for a zero length hash that covers the whole world");

        // check if hash is on edge and direction would push us over the edge
        // if so, wrap round to the other limit for longitude
        // or if at latitude boundary (a pole) then spin longitude around 180
        // degrees.
        LatLong centre = decodeHash(hash);

        // if rightmost hash
        if (Direction.RIGHT.equals(direction)
                && Math.abs(centre.getLon() + widthDegrees(hash.length()) / 2
                        - 180) < PRECISION) {
            return encodeHash(centre.getLat(), -180, hash.length());
        }
        // if leftmost hash
        if (Direction.LEFT.equals(direction)
                && Math.abs(centre.getLon() - widthDegrees(hash.length()) / 2
                        + 180) < PRECISION) {
            return encodeHash(centre.getLat(), 180, hash.length());
        }
        // if topmost hash
        if (Direction.TOP.equals(direction)
                && Math.abs(centre.getLat() + widthDegrees(hash.length()) / 2
                        - 90) < PRECISION) {
            return encodeHash(centre.getLat(), centre.getLon() + 180,
                    hash.length());
        }
        // if bottommost hash
        if (Direction.BOTTOM.equals(direction)
                && Math.abs(centre.getLat() - widthDegrees(hash.length()) / 2
                        + 90) < PRECISION) {
            return encodeHash(centre.getLat(), centre.getLon() + 180,
                    hash.length());
        }

        String source = hash.toLowerCase();
        char lastChar = source.charAt(source.length() - 1);
        Parity parity = (source.length() % 2 == 0) ? Parity.EVEN : Parity.ODD;
        String base = source.substring(0, source.length() - 1);
        if (BORDERS.get(direction).get(parity).indexOf(lastChar) != -1)
            base = adjacentHash(base, direction);
        return base
                + BASE32.charAt(NEIGHBOURS.get(direction).get(parity)
                        .indexOf(lastChar));
    }

from geohash-js.

tracker1 avatar tracker1 commented on August 19, 2024

Some examples...

I only ask, and it probably won't affect me (or most).. but notice that the geocode-js demo had problems with locations near the anti-meridian.

http://openlocation.org/geohash/geohash-js

beringovsky - 3 for matching
kabara island - 3 matching

from geohash-js.

Related Issues (4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.