GithubHelp home page GithubHelp logo

locate's People

Contributors

cbeloch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

mattisg

locate's Issues

[Enhancement] Locate should not implement distanceTo

For cleaner code the base class "Locate" should not implement more functions than needed. Think of the mootools philosophy. Please implement "distanceTo" in an extended "Locate" class.

Number.extend({
    // Converts the number in degrees to the radian equivalent
    deg2rad: function(angle){
        return (angle / 180) * Math.PI;
    }
});

Location.Measure = {

    OFFSET: 268435456,
    RADIUS: 85445659.4471, // offset / PI

    // Distance between two points on earth can be calculated in several ways.
    // Haversine formula  is reasonably accurate and widely used.
    haversineDistance: function(lat1, lng1, lat2, lng2){
        var latd = Number.deg2rad(lat2 - lat1);
        var lngd = Number.deg2rad(lng2 - lng1);
        var a = Number.sin(latd / 2) * Number.sin(latd / 2) +
        Number.cos(Number.deg2rad(lat1)) * Number.cos(Number.deg2rad(lat2)) *
        Number.sin(lngd / 2) *
        Number.sin(lngd / 2);
        var c = 2 * Number.atan2(Number.sqrt(a), Number.sqrt(1 - a));
        return 6371.0 * c;
    },

    lngToX: function(lng){
        return Number.round(this.OFFSET + this.RADIUS * lng * Math.PI / 180);
    },

    latToY: function(lat){
        return Number.round(this.OFFSET -
        this.RADIUS *
        Number.log((1 + Number.sin(lat * Math.PI / 180)) /
        (1 - Number.sin(lat * Math.PI / 180))) /
        2);
    },

    pixelDistance: function(y1, x1, y2, x2, zoom){
        if (y1 == y2 && x1 == x2) 
            return 0;
        return Number.sqrt(Number.pow((x1 - x2), 2) + Number.pow((y1 - y2), 2)) >> (21 - zoom);
    }
}

greetings André

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.