コード例 #1
0
        //Calling package:BingGeocoder to return address GEO coding
        private static List <GEOCodeStep> BingGeocoderList(string address, string webService, string key)
        {
            var    geoCodeStepsList = new List <GEOCodeStep>();
            string apikey           = GetConfigFile().IniReadValue(webService, key);

            try
            {
                BingGeocoderClient bingClient = new BingGeocoderClient(apikey);
                BingGeocoderResult bingResult = new BingGeocoderResult();
                bingResult = bingClient.Geocode(address);
                if (bingResult.Latitude != null && bingResult.Longitude != null)
                {
                    var geoCodeSteps = new GEOCodeStep();
                    geoCodeSteps.Status = "OK";
                    geoCodeSteps.lat    = bingResult.Latitude;
                    geoCodeSteps.lng    = bingResult.Longitude;
                    geoCodeStepsList.Add(geoCodeSteps);
                }
                else
                {
                    var geoCodeSteps = new GEOCodeStep();
                    //geoCodeSteps.Status = respStatus;
                    geoCodeSteps.lat = "ZERO_RESULTS";
                    geoCodeSteps.lng = "ZERO_RESULTS";
                    geoCodeStepsList.Add(geoCodeSteps);
                }
            }
            catch (Exception ex)
            {
                RecordLog("BingGeocoderList", ex.Message);
                return(null);
            }

            return(geoCodeStepsList);
        }
コード例 #2
0
        //Parsing response to get BING GEO Coding (lat and lng)
        private static List <GEOCodeStep> ParseBingGeoCodeResults(string result)
        {
            var geoCodeStepsList = new List <GEOCodeStep>();

            try
            {
                var jsonObject = JObject.Parse(result);
                var respArray  = (JArray)jsonObject["resourceSets"];
                var respStatus = jsonObject["statusCode"].ToString().Trim();

                var resultArray = (JArray)respArray[0]["resources"];
                if (respStatus == "200" && resultArray.Count >= 1)
                {
                    var geoCodeSteps = new GEOCodeStep();
                    var geoArray     = (JArray)resultArray[0]["point"]["coordinates"];
                    geoCodeSteps.Status = respStatus;
                    geoCodeSteps.lat    = geoArray[0].ToString();
                    geoCodeSteps.lng    = geoArray[1].ToString();
                    geoCodeStepsList.Add(geoCodeSteps);
                }
                else
                {
                    var geoCodeSteps = new GEOCodeStep();
                    geoCodeSteps.Status = respStatus;
                    geoCodeSteps.lat    = "ZERO_RESULTS";
                    geoCodeSteps.lng    = "ZERO_RESULTS";
                    geoCodeStepsList.Add(geoCodeSteps);
                }
            }
            catch (Exception e)
            {
                RecordLog("ParseBingGeoCodeResults", e.Message);
                return(null);
            }

            return(geoCodeStepsList);
        }
コード例 #3
0
        //Parsing response to get Google GEO Coding (lat and lng)
        private static List <GEOCodeStep> ParseGeoCodeResults(string result)
        {
            var geoCodeStepsList = new List <GEOCodeStep>();
            var xmlDoc           = new XmlDocument {
                InnerXml = result
            };

            if (xmlDoc.HasChildNodes)
            {
                var geoCodeResponseNode = xmlDoc.SelectSingleNode("GeocodeResponse");
                if (geoCodeResponseNode != null)
                {
                    var statusNode = geoCodeResponseNode.SelectSingleNode("status");
                    var lat        = geoCodeResponseNode.SelectSingleNode("result/geometry/location/lat");
                    var lng        = geoCodeResponseNode.SelectSingleNode("result/geometry/location/lng");
                    if (statusNode.InnerText.Equals("OK"))
                    {
                        var locs         = geoCodeResponseNode.SelectNodes("result/geometry/location");
                        var geoCodeSteps = new GEOCodeStep();
                        geoCodeSteps.Status = statusNode.InnerText;
                        geoCodeSteps.lat    = lat.InnerText;
                        geoCodeSteps.lng    = lng.InnerText;
                        geoCodeStepsList.Add(geoCodeSteps);
                    }
                    else
                    {
                        var geoCodeSteps = new GEOCodeStep();
                        geoCodeSteps.Status = statusNode.InnerText;
                        geoCodeSteps.lat    = "ZERO_RESULTS";
                        geoCodeSteps.lng    = "ZERO_RESULTS";
                        geoCodeStepsList.Add(geoCodeSteps);
                    }
                }
            }
            return(geoCodeStepsList);
        }