|
<< Click to Display Table of Contents >> Obter posicionamento via web |
![]() ![]()
|
using Newtonsoft.Json;
using System;
using System.Net;
namespace ConsoleApp4
{
public class Dados
{
public string City { get; set; }
public string Country { get; set; }
public decimal Lat { get; set; }
public decimal Lon { get; set; }
public string Region { get; set; }
public string RegionName { get; set; }
}
class Program
{
static void Main(string[] args)
{
using (WebClient wc = new WebClient())
{
var json = wc.DownloadString("http://ip-api.com/json");
Dados dados = JsonConvert.DeserializeObject<Dados>(json);
Console.WriteLine(String.Format("Cidade: {0}\nPaís: {1}\nLat/Lon: {2} | {3}\nEstado: {4} ({5})", dados.City, dados.Country, dados.Lat, dados.Lon, dados.Region, dados.RegionName));
Console.ReadLine();
}
}
}
}
References
System.Net;
Newtonsoft.Json;
Saída
Cidade: Criciuma
País: Brazil
Lat/Lon: -28,721 | -49,3872
Estado: SC (Santa Catarina)