public async Task <Location> getLocation(string location)
        {
            string url = "https://maps.googleapis.com/maps/api/geocode/json?address=" + location + "&key=" + geoCoding_api_key;

            string mycontent = "";


            using (var client = new HttpClient())
            {
                using (HttpResponseMessage response = await client.GetAsync(url))
                {
                    using (var content = response.Content)
                    {
                        mycontent = await content.ReadAsStringAsync();

                        JObject      o    = JObject.Parse(mycontent);
                        LocationRoot item = JsonConvert.DeserializeObject <LocationRoot>(o.ToString(), new JsonSerializerSettings()
                        {
                            DefaultValueHandling = DefaultValueHandling.Ignore
                        });

                        //string jsonString = JsonConvert.SerializeObject(item, Formatting.Indented);

                        //return jsonString;
                        //return o.ToString();
                        return(item.results[0].geometry.location);
                    }
                }
            }
        }
Example #2
0
        public static LocationRoot SageCostCentreToMTLocation(SageCostCentre sagecostcentre)
        {
            LocationRoot locationroot = new LocationRoot();
            Location     location     = new Location();

            location.id           = "";
            location.externalId   = sagecostcentre.PrimaryKey.DbValue.ToString();
            location.subsidiaries = null;
            location.name         = sagecostcentre.Name;
            location.active       = true;       // NO MATCHING FIELD IN SAGE

            locationroot.location = location;
            return(locationroot);
        }