Giter Club home page Giter Club logo

googlemaps.timezoneservices's Introduction

GoogleMaps.TimeZoneServices

A simple Library (Including nuget package) for Google Maps Time Zone API

Google documentation on the used API can be found at (https://developers.google.com/maps/documentation/timezone)

The easiest way to get hold of it is to install the Nuget package.

Example Lookup

      TzLatLong[] mapPoints = new TzLatLong[]
           {
                new TzLatLong // Amsterdam, Netherlands
                {
                    Latitude=52.3702157,
                    Longitude=4.89516790
                },
                new TzLatLong // London, England
                {
                    Latitude=51.5073509,
                    Longitude=-0.12775830
                },
                new TzLatLong // Mexico city, Mexico
                {
                    Latitude=19.4326077,
                    Longitude=-99.133208
                }
           };

      var gtzs = new GoogleTimeZoneServices(YOUR_GOOGLE_API_KEY);

      // Without Daylight saving time
      System.Console.WriteLine("=== DST not taken in conciduration ===");
      foreach (var mapPoint in mapPoints)
      {
        try
        {
          var timeZone = gtzs.GetTimeZoneFromLatLong(mapPoint.Latitude, mapPoint.Longitude);
          System.Console.WriteLine("TimeZone {0} found for point {1},{2}", timeZone, mapPoint.Latitude, mapPoint.Longitude);
        }
        catch (System.Net.WebException ex)
        {
          System.Console.WriteLine("Google Maps API Error {0}", ex.Message);
        } 

      }

      // With Daylight saving time
      System.Console.WriteLine("=== On 26 march 2017 at 3:01:00 AM (London and Amsterdam should have DST enabled ===");
      foreach (var mapPoint in mapPoints)
      {
        try
        {
          var timeZone = gtzs.GetTimeZoneWithDstFromLatLong(mapPoint.Latitude, mapPoint.Longitude, new DateTime(2017, 3, 26, 3, 1, 0));
          System.Console.WriteLine("TimeZone {0} found for point {1},{2}", timeZone, mapPoint.Latitude, mapPoint.Longitude);
        }
        catch (System.Net.WebException ex)
        {
          System.Console.WriteLine("Google Maps API Error {0}", ex.Message);
        }

      }
      System.Console.ReadLine();

googlemaps.timezoneservices's People

Contributors

xanore 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.