Exemplo n.º 1
0
        public IGeoCodeResult GetCoordinates(string search)
        {
            GeoCodeResult gResult = new GeoCodeResult();

            gResult.Library = this.GetType().ToString();
            if (!String.IsNullOrEmpty(Config.Key))
            {
                try
                {
                    string url  = BuildSearchQuery(search); //135+pilkington+avenue,+birmingham
                    string json = new WebRequester(url).GetData();
                    if (!String.IsNullOrEmpty(json))
                    {
                        JObject result = (JObject)JsonConvert.DeserializeObject(json);
                        if (result["results"][0]["locations"].Count() > 0)
                        {
                            foreach (var loc in result["results"][0]["locations"])
                            {
                                try
                                {
                                    Location l      = new Location();
                                    var      latLng = loc["latLng"];
                                    if (latLng != null)
                                    {
                                        l.Latitude  = latLng["lat"].GetDoubleValue();
                                        l.Longitude = latLng["lng"].GetDoubleValue();
                                    }

                                    l.Accuracy = loc["geocodeQuality"].GetStringValue();

                                    String[] AddressTemp = new string[]
                                    {
                                        loc["street"].GetStringValue(),
                                        loc["adminArea5"].GetStringValue(),
                                        loc["adminArea4"].GetStringValue(),
                                        loc["postalCode"].GetStringValue(),
                                        loc["adminArea1"].GetStringValue()
                                    };

                                    l.Type    = loc["type"].GetStringValue();
                                    l.Address = String.Join(",", AddressTemp.Where(s => !String.IsNullOrEmpty(s)));
                                    l.Name    = l.Address;

                                    gResult.Locations.Add(l);
                                }
                                catch
                                {
                                }
                            }
                        }
                        //gResult.Count = 1;
                    }
                }
                catch
                {
                }
            }
            return(gResult);
        }
Exemplo n.º 2
0
 public void Prepare(DisclaimerNavigation parameter)
 {
     _address     = parameter.AddressResult;
     _accessToken = parameter.AccessToken;
     _firstname   = parameter.Firstname;
     _lastname    = parameter.Lastname;
     _userId      = parameter.UserId;
 }
 public DisclaimerNavigation(string userId, string accessToken, string firstname, string lastname, GeoCodeResult addressResult)
 {
     UserId        = userId;
     AccessToken   = accessToken;
     Firstname     = firstname;
     Lastname      = lastname;
     AddressResult = addressResult;
 }
Exemplo n.º 4
0
        public IGeoCodeResult GetCoordinates(string search)
        {
            GeoCodeResult gResult = new GeoCodeResult();
            gResult.Library = this.GetType().ToString();
            try
            {
                string url = BuildSearchQuery(search); //1600+Amphitheatre+Parkway,+Mountain+View,+CA
                string json = new WebRequester(url).GetData();
                if (!String.IsNullOrEmpty(json))
                {
                    JObject result = (JObject)JsonConvert.DeserializeObject(json);
                    if (result["status"].GetStringValue() == GoogleResultStatus.OK.ToString() && result["results"].Count()>0)
                    {

                        foreach (var loc in result["results"])
                        {
                            Location Location = new Location();

                            Location.Address = loc["formatted_address"].GetStringValue();

                            var geometry = loc["geometry"];
                            if (geometry != null)
                            {
                                var location = geometry["location"];
                                if (location != null)
                                {
                                    Location.Latitude = location["lat"].GetDoubleValue();
                                    Location.Longitude = location["lng"].GetDoubleValue();
                                }

                                Location.Type = location["location_type"].GetStringValue();

                            }

                            var addresscomponents = loc["address_components"];
                            if (addresscomponents != null && addresscomponents.Count() > 0)
                            {
                                Location.Name = loc["address_components"][0]["long_names"].GetStringValue(); //!String.IsNullOrEmpty(loc["address_components"][0]["long_name"].Value<String>()) ? loc["address_components"][0]["long_name"].Value<String>() : string.Empty;
                            }
                            gResult.Locations.Add(Location);
                        }

                    }
                    else
                    {
                        gResult.Error = result["status"].ToString();
                    }
                }

            }
            catch (Exception e)
            {
                gResult.Error = e.Message;
            }

            return gResult;
        }
Exemplo n.º 5
0
        public IGeoCodeResult GetCoordinates(string search)
        {
            GeoCodeResult gResult = new GeoCodeResult();
            gResult.Library = this.GetType().ToString();
            try
            {
                string url = BuildSearchQuery(search); //1600+Amphitheatre+Parkway,+Mountain+View,+CA
                string json = new WebRequester(url).GetData();
                if (!String.IsNullOrEmpty(json))
                {
                    JObject result = (JObject)JsonConvert.DeserializeObject(json);
                    if (result["found"].Value<int>() > 0)
                    {
                        foreach (var loc in result["features"])
                        {
                            Location Location = new Location();

                            var properties = loc["properties"];
                            if (properties != null)
                            {
                                Location.Name = properties["name"].GetStringValue();

                                Location.Address = Location.Name;
                                Location.Type = properties["place"].GetStringValue();

                            }

                            var centroid = loc["centroid"];
                            if (centroid != null)
                            {
                                var coordinates = centroid["coordinates"];
                                if (coordinates != null && coordinates.Count() > 1)
                                {
                                    Location.Latitude = coordinates[0].GetDoubleValue();
                                    Location.Longitude = coordinates[1].GetDoubleValue();
                                }

                            }

                            gResult.Locations.Add(Location);
                        }

                    }
                    else
                    {
                        gResult.Error = "No results";
                    }
                }

            }
            catch (Exception e)
            {
                gResult.Error = e.Message;
            }

            return gResult;
        }
Exemplo n.º 6
0
        public void GoogleGmapAmbiguous()
        {
            GoogleGmap g = new GoogleGmap();

            IGeoCodeResult Target = new GeoCodeResult();

            Target = g.GetCoordinates("Paris");
            Assert.IsTrue(Target.Count > 0);
        }
Exemplo n.º 7
0
        /// <summary>
        /// 获取地理编码信息
        /// </summary>
        /// <param name="geoCodeParam">地理编码所需参数</param>
        /// <returns>地理编码信息</returns>
        public GeoCodeResult GetGeoCode(GeoCodeParam geoCodeParam)
        {
            string getUrl = "https://restapi.amap.com/v3/geocode/geo?{0}";
            string paras  = QueryHelper.ToQueryString(geoCodeParam);

            getUrl = string.Format(getUrl, paras);
            GeoCodeResult geoCodeResult = SimulateRequest.HttpGet <GeoCodeResult>(getUrl);

            return(geoCodeResult);
        }
Exemplo n.º 8
0
        public IGeoCodeResult GetCoordinates(string search)
        {
            GeoCodeResult gResult = new GeoCodeResult();
            gResult.Library = this.GetType().ToString();
            if (!String.IsNullOrEmpty(Config.Key))
            {
                try
                {
                    string url = BuildSearchQuery(search); //135+pilkington+avenue,+birmingham
                    string json = new WebRequester(url).GetData();
                    if (!String.IsNullOrEmpty(json))
                    {
                        JObject result = (JObject)JsonConvert.DeserializeObject(json);
                        if (result["resourceSets"][0]["resources"].Count() > 0)
                        {
                            foreach (var loc in result["resourceSets"][0]["resources"])
                            {
                                Location l = new Location();
                                String AddressTemp = String.Empty;
                                l.Name = loc["name"].GetStringValue();

                                var point = loc["point"];
                                if (point != null && point.Count()>1)
                                {
                                    l.Latitude = point["coordinates"][0].GetDoubleValue();
                                    l.Longitude = point["coordinates"][1].GetDoubleValue();
                                }

                                l.Accuracy = loc["confidence"].GetStringValue();
                                if (loc["address"].HasValues)
                                {
                                    AddressTemp = String.Join(",", loc["address"].Values().Where(add => !string.IsNullOrEmpty(add.Value<string>())));
                                }
                                l.Address = AddressTemp;
                                gResult.Locations.Add(l);
                            }

                            //gResult.Count = 1; // for now we are only dealing with the first result
                        }
                        else
                        {
                            gResult.Error = "No Results";

                        }

                    }

                }
                catch
                {

                }
            }
            return gResult;
        }
Exemplo n.º 9
0
        public IGeoCodeResult GetCoordinates(string search)
        {
            GeoCodeResult gResult = new GeoCodeResult();

            gResult.Library = this.GetType().ToString();
            try
            {
                string url  = BuildSearchQuery(search); //1600+Amphitheatre+Parkway,+Mountain+View,+CA
                string json = new WebRequester(url).GetData();
                if (!String.IsNullOrEmpty(json))
                {
                    JObject result = (JObject)JsonConvert.DeserializeObject(json);
                    if (result["status"].GetStringValue() == GoogleResultStatus.OK.ToString() && result["results"].Count() > 0)
                    {
                        foreach (var loc in result["results"])
                        {
                            Location Location = new Location();


                            Location.Address = loc["formatted_address"].GetStringValue();

                            var geometry = loc["geometry"];
                            if (geometry != null)
                            {
                                var location = geometry["location"];
                                if (location != null)
                                {
                                    Location.Latitude  = location["lat"].GetDoubleValue();
                                    Location.Longitude = location["lng"].GetDoubleValue();
                                }

                                Location.Type = location["location_type"].GetStringValue();
                            }

                            var addresscomponents = loc["address_components"];
                            if (addresscomponents != null && addresscomponents.Count() > 0)
                            {
                                Location.Name = loc["address_components"][0]["long_names"].GetStringValue(); //!String.IsNullOrEmpty(loc["address_components"][0]["long_name"].Value<String>()) ? loc["address_components"][0]["long_name"].Value<String>() : string.Empty;
                            }
                            gResult.Locations.Add(Location);
                        }
                    }
                    else
                    {
                        gResult.Error = result["status"].ToString();
                    }
                }
            }
            catch (Exception e)
            {
                gResult.Error = e.Message;
            }

            return(gResult);
        }
Exemplo n.º 10
0
 public static string GetFirstAddressPart(this GeoCodeResult result, string part)
 {
     try
     {
         return(result.GetFirstAddressProperty(GetAddressPartSelector(part)));
     }
     catch (Exception)
     {
         return("");
     }
 }
Exemplo n.º 11
0
 public static string GetFirstFormattedAddress(this GeoCodeResult result)
 {
     try
     {
         return(result.GetFirstAddressProperty(a => a.formattedAddress));
     }
     catch (Exception)
     {
         return("");
     }
 }
Exemplo n.º 12
0
        public IGeoCodeResult GetCoordinates(string search)
        {
            GeoCodeResult gResult = new GeoCodeResult();

            gResult.Library = this.GetType().ToString();
            try
            {
                string url  = BuildSearchQuery(search); //1600+Amphitheatre+Parkway,+Mountain+View,+CA
                string json = new WebRequester(url).GetData();
                if (!String.IsNullOrEmpty(json))
                {
                    JObject result = (JObject)JsonConvert.DeserializeObject(json);
                    if (result["found"].Value <int>() > 0)
                    {
                        foreach (var loc in result["features"])
                        {
                            Location Location = new Location();

                            var properties = loc["properties"];
                            if (properties != null)
                            {
                                Location.Name = properties["name"].GetStringValue();

                                Location.Address = Location.Name;
                                Location.Type    = properties["place"].GetStringValue();
                            }

                            var centroid = loc["centroid"];
                            if (centroid != null)
                            {
                                var coordinates = centroid["coordinates"];
                                if (coordinates != null && coordinates.Count() > 1)
                                {
                                    Location.Latitude  = coordinates[0].GetDoubleValue();
                                    Location.Longitude = coordinates[1].GetDoubleValue();
                                }
                            }

                            gResult.Locations.Add(Location);
                        }
                    }
                    else
                    {
                        gResult.Error = "No results";
                    }
                }
            }
            catch (Exception e)
            {
                gResult.Error = e.Message;
            }

            return(gResult);
        }
Exemplo n.º 13
0
 public static Address GetFirstAddress(this GeoCodeResult result)
 {
     try
     {
         return(result.GetAddresses().FirstOrDefault());
     }
     catch (Exception)
     {
         return(null);
     }
 }
Exemplo n.º 14
0
 public static Tuple <double, double> GetFirstCoordinate(this GeoCodeResult result)
 {
     try
     {
         return(result.GetCoordinates().FirstOrDefault() ?? new Tuple <double, double>(0, 0));
     }
     catch (Exception)
     {
         return(new Tuple <double, double>(0, 0));
     }
 }
Exemplo n.º 15
0
        public void YahooPlaceFinder()
        {
            YahooPlaceFinder g = new YahooPlaceFinder();

            var Expected = new { Latitude = 30.267605, Longitude = -97.742984 };

            IGeoCodeResult Target = new GeoCodeResult();

            Target = g.GetCoordinates("Austin, TX");
            Assert.AreEqual(Expected.Latitude, Target.Latitude);
            Assert.AreEqual(Expected.Longitude, Target.Longitude);
        }
Exemplo n.º 16
0
        public void GoogleMapNoResults()
        {
            GoogleGmapConfig gmc = new GoogleGmapConfig();

            GoogleGmap g = new GoogleGmap(gmc);

            IGeoCodeResult Target = new GeoCodeResult();

            Target = g.GetCoordinates("alskdfjkaadsflasd");
            Assert.AreEqual(false, Target.HasValue);
            Assert.AreEqual(0, Target.Longitude);
        }
Exemplo n.º 17
0
        public void CloudMade()
        {
            CloudMade g = new CloudMade(new CloudMadeConfig().SetKey(CloudMadeApi));

            var Expected = new { Latitude = -28.85422, Longitude = 151.16864 };

            IGeoCodeResult Target = new GeoCodeResult();

            Target = g.GetCoordinates("Austin, TX");
            Assert.AreEqual(Expected.Latitude, Target.Latitude);
            Assert.AreEqual(Expected.Longitude, Target.Longitude);
        }
Exemplo n.º 18
0
        public IGeoCodeResult GetCoordinates(string search)
        {
            GeoCodeResult gResult = new GeoCodeResult();

            gResult.Library = this.GetType().ToString();
            if (!String.IsNullOrEmpty(Config.Key))
            {
                try
                {
                    string url  = BuildSearchQuery(search); //135+pilkington+avenue,+birmingham
                    string json = new WebRequester(url).GetData();
                    if (!String.IsNullOrEmpty(json))
                    {
                        JObject result = (JObject)JsonConvert.DeserializeObject(json);
                        if (result["resourceSets"][0]["resources"].Count() > 0)
                        {
                            foreach (var loc in result["resourceSets"][0]["resources"])
                            {
                                Location l           = new Location();
                                String   AddressTemp = String.Empty;
                                l.Name = loc["name"].GetStringValue();

                                var point = loc["point"];
                                if (point != null && point.Count() > 1)
                                {
                                    l.Latitude  = point["coordinates"][0].GetDoubleValue();
                                    l.Longitude = point["coordinates"][1].GetDoubleValue();
                                }

                                l.Accuracy = loc["confidence"].GetStringValue();
                                if (loc["address"].HasValues)
                                {
                                    AddressTemp = String.Join(",", loc["address"].Values().Where(add => !string.IsNullOrEmpty(add.Value <string>())));
                                }
                                l.Address = AddressTemp;
                                gResult.Locations.Add(l);
                            }

                            //gResult.Count = 1; // for now we are only dealing with the first result
                        }
                        else
                        {
                            gResult.Error = "No Results";
                        }
                    }
                }
                catch
                {
                }
            }
            return(gResult);
        }
        /// <summary>
        /// 获取地理编码信息
        /// </summary>
        /// <param name="geoCodeParam">地理编码所需参数</param>
        /// <returns>地理编码信息</returns>
        public GeoCodeResult GetGeoCode(GeoCodeParam geoCodeParam)
        {
            geoCodeParam.output = "JSON";
            string jsonResult = GetOriginalGeoCode(geoCodeParam);

            if (!string.IsNullOrWhiteSpace(jsonResult))
            {
                jsonResult = jsonResult.Replace("[]", "\"\"");
            }
            GeoCodeResult geoCodeResult = JsonConvert.DeserializeObject <GeoCodeResult>(jsonResult);

            return(geoCodeResult);
        }
Exemplo n.º 20
0
 public static IEnumerable <Address> GetAddresses(this GeoCodeResult result)
 {
     try
     {
         return(from rs in result.resourceSets
                from r in rs.resources
                select r.address);
     }
     catch (Exception)
     {
         return(Enumerable.Empty <Address>());
     }
 }
Exemplo n.º 21
0
        public void BingMapNoResults()
        {
            BingMapConfig bmc = new BingMapConfig()
                                .SetKey(BingKey);

            BingMap bing = new BingMap(bmc);

            IGeoCodeResult Target = new GeoCodeResult();

            Target = bing.GetCoordinates("alskdfjkaadsflasd");
            Assert.AreEqual(false, Target.HasValue);
            Assert.AreEqual(0, Target.Longitude);
        }
Exemplo n.º 22
0
        public void OpenStreetsMapNoResults()
        {
            OpenStreetMap o = new OpenStreetMap();

            IGeoCodeResult Expected = new GeoCodeResult();

            Expected.Latitude  = 30.1968545;
            Expected.Longitude = -97.5975533560703;

            IGeoCodeResult Target = new GeoCodeResult();

            Target = o.GetCoordinates("asdfasdfaasdfasdfasd;fja");
            Assert.AreEqual(Target.HasValue, false);
        }
        public async Task <IEnumerable <Position> > GetPositionsForAddressAsync(string address)
        {
            if (!string.IsNullOrEmpty(address))
            {
                // Origin of route
                string addressQueryParam = $"address={WebUtility.UrlEncode(address)}";

                // Auth
                string key = $"key={AppSettings.GoogleMapsGeocodeAPIKey}";

                GeoCodeResult geoCodeData = default(GeoCodeResult);
                try
                {
                    // Building the parameters to the web service
                    string parameters = string.Join("&", new[] { addressQueryParam, key });

                    UriBuilder uri = new UriBuilder("https://maps.googleapis.com/maps/api/geocode/json");
                    uri.Query = parameters;

                    var requestProvider = new RequestProvider();
                    geoCodeData = await requestProvider.GetAsync <GeoCodeResult>(uri.ToString());
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine($"Error calling routes api from google: {ex}");
                    return(null);
                }

                if ("OK".Equals(geoCodeData?.Status, StringComparison.CurrentCultureIgnoreCase) &&
                    geoCodeData?.Results != null &&
                    geoCodeData.Results.Any())
                {
                    Collection <Position> result = new Collection <Position>();

                    foreach (var geoCodePosition in geoCodeData.Results)
                    {
                        if (geoCodePosition?.Geometry?.Location != null)
                        {
                            result.Add(new Position(
                                           geoCodePosition.Geometry.Location.Latitude,
                                           geoCodePosition.Geometry.Location.Longitude));
                        }
                    }

                    return(result);
                }
            }

            return(null);
        }
Exemplo n.º 24
0
 public static IEnumerable <Tuple <double, double> > GetCoordinates(this GeoCodeResult result)
 {
     try
     {
         return(from rs in result.resourceSets
                from r in rs.resources
                let pts = r.point.coordinates
                          select new Tuple <double, double>(pts[0], pts[1]));
     }
     catch (Exception)
     {
         return(Enumerable.Empty <Tuple <double, double> >());
     }
 }
Exemplo n.º 25
0
        public void GoogleGmap()
        {
            GoogleGmap g = new GoogleGmap();

            var Expected = new {
                Latitude  = 30.267153,
                Longitude = -97.7430608
            };

            IGeoCodeResult Target = new GeoCodeResult();

            Target = g.GetCoordinates("Austin, TX");
            Assert.AreEqual(Expected.Latitude, Target.Latitude);
            Assert.AreEqual(Expected.Longitude, Target.Longitude);
        }
Exemplo n.º 26
0
        public void OpenStreetsMap()
        {
            OpenStreetMap o = new OpenStreetMap();

            var Expected = new
            {
                Latitude  = 30.1968545,
                Longitude = -97.5975533560703
            };

            IGeoCodeResult Target = new GeoCodeResult();

            Target = o.GetCoordinates("Austin, TX");
            Assert.AreEqual(Expected.Latitude, Target.Latitude);
            Assert.AreEqual(Expected.Longitude, Target.Longitude);
        }
Exemplo n.º 27
0
        public void BingMapTest()
        {
            BingMapConfig bmc = new BingMapConfig()
                                .SetKey(BingKey);

            BingMap bing = new BingMap(bmc);

            var Expected = new {
                Latitude  = 30.267599105834961,
                Longitude = -97.74298095703125
            };
            IGeoCodeResult Target = new GeoCodeResult();

            Target = bing.GetCoordinates("Austin, TX");
            Assert.AreEqual(Expected.Latitude, Target.Latitude);
            Assert.AreEqual(Expected.Longitude, Target.Longitude);
        }
Exemplo n.º 28
0
        public void GeoCoderAlternate()
        {
            var Expected = new
            {
                Latitude  = 30.1968545,
                Longitude = -97.5975533560703
            };

            IGeoCodeResult Target = new GeoCodeResult();

            GeoCoder gc = new GeoCoder();

            gc.AddProvider(new OpenStreetMap());
            Target = gc.GetCoordinates("Austin, TX");
            Assert.AreEqual(Expected.Latitude, Target.Latitude);
            Assert.AreEqual(Expected.Longitude, Target.Longitude);
        }
Exemplo n.º 29
0
        public void GeoCoderYahooPlaceFinder()
        {
            YahooPlaceFinderConfig yph = new YahooPlaceFinderConfig().SetKey(YahooAppId);
            YahooPlaceFinder       ypf = new Lucuma.Libs.YahooPlaceFinder(yph);

            GeoCoder g = new GeoCoder(ypf);

            var Expected = new {
                Latitude  = 30.267605,
                Longitude = -97.742984
            };

            IGeoCodeResult Target = new GeoCodeResult();

            Target = g.GetCoordinates("Austin, TX");
            Assert.AreEqual(Expected.Latitude, Target.Latitude);
            Assert.AreEqual(Expected.Longitude, Target.Longitude);
        }
Exemplo n.º 30
0
        public static string GetFirstAddressProperty(this GeoCodeResult result, Func <Address, string> selector)
        {
            Debug.Assert(selector != null);

            try
            {
                var address = result.GetFirstAddress();
                if (address != null)
                {
                    return(selector(address));
                }
            }
            catch (Exception)
            {
            }

            return("");
        }
Exemplo n.º 31
0
        public void MapQuestMapNoResultsTest()
        {
            MapQuestConfig mqc = new MapQuestConfig()
                                 .SetKey(MapQuestKey);

            MapQuestMap MapQuest = new MapQuestMap(mqc);

            IGeoCodeResult Expected = new GeoCodeResult();

            Expected.Latitude  = 30.266899;
            Expected.Longitude = -97.742798;

            IGeoCodeResult Target = new GeoCodeResult();

            Target = MapQuest.GetCoordinates("zdkthqqad,aads,a");

            // mapquest seems to always return some result
        }
Exemplo n.º 32
0
        public void GeoCoderBingTest()
        {
            GeoCoder      gc  = new GeoCoder();
            BingMapConfig bmc = new BingMapConfig()
                                .SetKey(BingKey);

            gc.AddProvider(new BingMap(bmc));  // bing requires a key

            IGeoCodeResult Target = new GeoCodeResult();

            var Expected = new{
                Latitude  = 30.267599105834961,
                Longitude = -97.74298095703125
            };

            Target = gc.GetCoordinates("Austin, TX");
            Assert.AreEqual(Expected.Latitude, Target.Latitude);
            Assert.AreEqual(Expected.Longitude, Target.Longitude);
        }
Exemplo n.º 33
0
        public void MapQuestMapTest()
        {
            // mapquest is wierd and always returns some kind of result so not sure this test is valid.
            MapQuestConfig mqc = new MapQuestConfig()
                                 .SetKey(MapQuestKey);

            MapQuestMap MapQuest = new MapQuestMap(mqc);

            var Expected = new{
                Latitude  = 30.266899,
                Longitude = -97.742798
            };

            IGeoCodeResult Target = new GeoCodeResult();

            Target = MapQuest.GetCoordinates("Austin, TX");
            Assert.AreEqual(Expected.Latitude, Target.Latitude);
            Assert.AreEqual(Expected.Longitude, Target.Longitude);
        }
Exemplo n.º 34
0
        public IGeoCodeResult GetCoordinates(string search)
        {
            GeoCodeResult gResult = new GeoCodeResult();
            gResult.Library = this.GetType().ToString();
            try
            {
                string url = BuildSearchQuery(search); //135+pilkington+avenue,+birmingham
                string json = new WebRequester(url, Config.UserAgent).GetData();  // Open Street Maps wants the agent name set

                if (!String.IsNullOrEmpty(json))
                {
                    JArray result = (JArray)JsonConvert.DeserializeObject(json);
                    if (result.Count() > 0)
                    {
                        foreach (var loc in result)
                        {
                            Location l = new Location();
                            l.Name = loc["display_name"].GetStringValue();
                            l.Latitude = loc["lat"].GetDoubleValue();
                            l.Longitude = loc["lon"].GetDoubleValue();
                            l.Type = loc["type"].GetStringValue();
                            l.Address = l.Name;
                            gResult.Locations.Add(l);
                        }

                        //gResult.Count = 1;
                    }
                }
            }

            catch
            {

            }
            return gResult;
        }
Exemplo n.º 35
0
        public IGeoCodeResult GetCoordinates(string search)
        {
            GeoCodeResult gResult = new GeoCodeResult();
            gResult.Library = this.GetType().ToString();
            if (!String.IsNullOrEmpty(Config.Key))
            {
                try
                {
                    string url = BuildSearchQuery(search); //135+pilkington+avenue,+birmingham
                    string json = new WebRequester(url).GetData();
                    if (!String.IsNullOrEmpty(json))
                    {
                        JObject result = (JObject)JsonConvert.DeserializeObject(json);
                        if (result["results"][0]["locations"].Count() > 0)
                        {
                            foreach (var loc in result["results"][0]["locations"])
                            {
                                try
                                {
                                    Location Location = new Location();
                                    var latLng = loc["latLng"];
                                    if (latLng != null)
                                    {
                                        Location.Latitude = latLng["lat"].GetDoubleValue();
                                        Location.Longitude = latLng["lng"].GetDoubleValue();

                                    }

                                    Location.Accuracy = loc["geocodeQuality"].GetStringValue();

                                    String[] AddressTemp = new string[]
                                    {
                                        loc["street"].GetStringValue(),
                                        loc["adminArea5"].GetStringValue(),
                                        loc["adminArea4"].GetStringValue(),
                                        loc["postalCode"].GetStringValue(),
                                        loc["adminArea1"].GetStringValue()

                                    };

                                    Location.Type = loc["type"].GetStringValue();
                                    Location.Address = String.Join(",", AddressTemp.Where(s => !String.IsNullOrEmpty(s)));
                                    Location.Country = loc["adminArea1"].GetStringValue();
                                    Location.Name = Location.Address;

                                    gResult.Locations.Add(Location);
                                }
                                catch
                                {

                                }
                            }

                        }
                        //gResult.Count = 1;

                    }

                }
                catch
                {

                }
            }
            return gResult;
        }
Exemplo n.º 36
0
        public IGeoCodeResult GetCoordinates(string search)
        {
            GeoCodeResult gResult = new GeoCodeResult();
            gResult.Library = this.GetType().ToString();
            try
            {
                string url = BuildSearchQuery(search); //1600+Amphitheatre+Parkway,+Mountain+View,+CA
                string json = new WebRequester(url).GetData();
                if (!String.IsNullOrEmpty(json))
                {
                    JObject result = (JObject)JsonConvert.DeserializeObject(json);
                    if (result["ResultSet"]["Found"].Value<int>() > 0)
                    {
                        foreach (var loc in result["ResultSet"]["Results"])
                        {

                            Location Location = new Location();
                            try
                            {
                                string[] AddressStrings = new string[] {
                                loc["house"].GetStringValue(),
                                loc["street"].GetStringValue(),
                                loc["xstreet"].GetStringValue(),
                                loc["unit"].GetStringValue(),
                                loc["unittype"].GetStringValue(),
                                loc["postal"].GetStringValue(),
                                loc["neighborhood"].GetStringValue(),
                                loc["house"].GetStringValue(),
                                loc["city"].GetStringValue(),
                                loc["uzip"].GetStringValue(),
                                loc["county"].GetStringValue(),
                                loc["state"].GetStringValue(),
                                loc["country"].GetStringValue()
                                };
                                Location.Address = String.Join(",", AddressStrings.Where(s => !string.IsNullOrEmpty(s)));
                            }
                            catch { }

                            Location.Type = String.Concat(loc["woetype"].GetStringValue());

                            Location.Latitude = loc["latitude"].GetDoubleValue();
                            Location.Longitude = loc["longitude"].GetDoubleValue();
                            Location.Accuracy = loc["quality"].GetStringValue();
                            Location.Name = String.Concat(loc["line2"].GetStringValue(), loc["line4"].GetStringValue());
                            gResult.Locations.Add(Location);

                        }

                    }
                    else
                    {
                        gResult.Error = result["status"].ToString();
                    }
                }

            }
            catch (Exception e)
            {
                gResult.Error = e.Message;
            }

            return gResult;
        }