Exemplo n.º 1
0
        public static PlaceInformation GetPlacesInfo(Countries country, string stateCode, string city)
        {
            var result = new PlaceInformation();

            var returnedJson = Core.ExecuteStraight(country, stateCode, city);
            var o = JObject.Parse(returnedJson);

            result = JsonConvert.DeserializeObject<PlaceInformation>(returnedJson);
            result.CountryCode = (Countries)Enum.Parse(typeof(Countries), (string)o["country abbreviation"]);
            result.PlaceName = (string)o["place name"];
            result.StateCode = (string)o["state abbreviation"];

            var places = (JArray)o["places"];

            for (var i = 0; i < places.Count; i++)
            {
                var newPlace       = new Place();
                newPlace.PlaceName = (string)places[i]["place name"];
                newPlace.Longitude = double.Parse((string)places[i]["longitude"], CultureInfo.InvariantCulture);
                newPlace.Latitude  = double.Parse((string)places[i]["latitude"], CultureInfo.InvariantCulture);
                newPlace.ZipCode   = (string)places[i]["post code"];
                result.Places.Add(newPlace);
            }

            return result;
        }
Exemplo n.º 2
0
        public static ZipCodeInfo GetPostalCodeInfo(Countries contry, string zipCode)
        {
            var result = new ZipCodeInfo();

            var returnedJson = Core.ExecuteStraight(contry, zipCode);
            var o = JObject.Parse(returnedJson);

            result = JsonConvert.DeserializeObject<ZipCodeInfo>(returnedJson);
            result.PostalCode = o["post code"].ToString();
            result.CountryCode = (Countries)Enum.Parse(typeof(Countries), o["country abbreviation"].ToString());

            var places = o["places"] as JArray;

            for (var i = 0; i < places.Count; i++)
            {
                var place = new Place();

                place.PlaceName = places[i]["place name"].ToString();
                place.StateAbbreviation = places[i]["state abbreviation"].ToString();
                result.Places.Add(place);
            }

            return result;
        }