-
-
Save thiagoloureiro/02a2fd3f162dcb026d8b7a318d8f5dd6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Newtonsoft.Json; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Net; | |
using Velyo.Google.Services.Models; | |
namespace CepApp | |
{ | |
public class AddressUtil | |
{ | |
public class Location | |
{ | |
public double lat { get; set; } | |
public double lng { get; set; } | |
} | |
public class Geometry | |
{ | |
public Bounds bounds { get; set; } | |
public Location location { get; set; } | |
public string location_type { get; set; } | |
// public Viewport viewport { get; set; } | |
} | |
public class Result | |
{ | |
public List<AddressComponent> address_components { get; set; } | |
public string formatted_address { get; set; } | |
public Geometry geometry { get; set; } | |
public string place_id { get; set; } | |
public List<string> types { get; set; } | |
} | |
public class RootObject | |
{ | |
public List<Result> results { get; set; } | |
public string status { get; set; } | |
} | |
public static RootObject GetLatLongByAddress(string address) | |
{ | |
var root = new RootObject(); | |
var url = | |
string.Format( | |
"http://maps.googleapis.com/maps/api/geocode/json?address={0}&sensor=true_or_false", address); | |
var req = (HttpWebRequest)WebRequest.Create(url); | |
var res = (HttpWebResponse)req.GetResponse(); | |
using (var streamreader = new StreamReader(res.GetResponseStream())) | |
{ | |
var result = streamreader.ReadToEnd(); | |
if (!string.IsNullOrWhiteSpace(result)) | |
{ | |
root = JsonConvert.DeserializeObject<RootObject>(result); | |
} | |
} | |
return root; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment