Articles → .NET → Get location information in windows 7 without location sensor in C#

Get location information in windows 7 without location sensor in C#








Service for getting location





Code to get location




using Newtonsoft.Json;
using System;
using System.Net.Http;

namespace ReadJson {
  class Program {
    static void Main(string[] args) {
      using(HttpClient client = new HttpClient()) {
        client.BaseAddress = new Uri("http://ip-api.com");
        HttpResponseMessage response = client.GetAsync("/json").Result; // Blocking call!  
        if (response.IsSuccessStatusCode) {
          dynamic stuff = JsonConvert.DeserializeObject(response.Content.ReadAsStringAsync().Result);

          Console.WriteLine(stuff.lat);
          Console.WriteLine(stuff.lon);
          Console.ReadLine();
        }
      }

    }
  }
}





Posted By  -  Karan Gupta
 
Posted On  -  Wednesday, March 15, 2017

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250