Giter Site home page Giter Site logo

github2017luo / geolocation Goto Github PK

View Code? Open in Web Editor NEW

This project forked from scottschluer/geolocation

0.0 1.0 0.0 1.1 MB

A C# class library that will calculate distance and cardinal direction between two sets of coordinates and provides the lat/long boundaries around an origin coordinate allowing for simple SQL or LINQ selection of locations within the given radius.

License: MIT License

C# 90.02% ASP 0.10% HTML 9.17% CSS 0.67% JavaScript 0.03%

geolocation's Introduction

Added Support for .Net Core

USAGE:

All methods support passing Coordinate objects as parameters as well as decimal lat/long values. Assuming the following Coordinate objects, the examples below show two different ways to make the same call:

Coordinate origin = new Coordinate(34.0675918, -118.3977091);
Coordinate destination = new Coordinate(34.076234, -118.395314);

Find the distance between two points in miles:

double distance = GeoCalculator.GetDistance(34.0675918, -118.3977091, 34.076234, -118.395314, 1);
//OR
double distance = GeoCalculator.GetDistance(origin, destination, 1);

Find the cardinal direction (e.g. N, NW, W) from an origin coordinate to a destination coordinate:

string direction = GeoCalculator.GetDirection(34.0675918, -118.3977091, 34.076234, -118.395314);
//OR
string direction = GeoCalculator.GetDirection(origin, destination);

Find the bearing (degrees) from an origin coordinate to a destination coordinate:

double bearing = GeoCalculator.GetBearing(34.0675918, -118.3977091, 34.076234, -118.395314);
//OR
double bearing = GeoCalculator.GetBearing(origin, destination);

Find the lat/long boundaries for a given origin coordinate and radius:

CoordinateBoundaries boundaries = new CoordinateBoundaries(34.0675918, -118.3977091, 25);
//OR
CoordinateBoundaries boundaries = new CoordinateBoundaries(origin, 25);
  
double minLatitude = boundaries.MinLatitude;
double maxLatitude = boundaries.MaxLatitude;
double minLongitude = boundaries.MinLongitude;
double maxLongitude = boundaries.MaxLongitude;

var results = _locations
  .Where(x => x.Latitude >= minLatitude && x.Latitude <= maxLatitude)
  .Where(x => x.Longitude >= minLongitude && x.Longitude <= maxLongitude)
  .Select(result => new 
  {
    Name = result.Name,
    Distance = GeoCalculator.GetDistance(origin.Latitude, origin.Longitude, result.Latitude, result.Longitude, 1),
    Direction = GeoCalculator.GetDirection(origin.Latitude, origin.Longitude, result.Latitude, result.Longitude)
  })
  .Where(x => x.Distance <= 25)
  .OrderBy(x => x.Distance);

geolocation's People

Contributors

jfmg avatar scottschluer avatar shakuskyleigh avatar

Watchers

 avatar

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.