/// <summary>
        /// Call google api to get nearby stores and return the result
        /// </summary>
        /// <param name="zip"></param>
        /// <param name="storeType"></param>
        /// <returns></returns>
        public string findNearestStore(string zip, string storeType)
        {
            ServiceReferenceWebToString.ServiceClient proxyWebToString = new ServiceReferenceWebToString.ServiceClient();
            string longLat = getLatLong(zip);
            string radius  = "5000"; //5 km

            string url = "https://maps.googleapis.com/maps/api/place/nearbysearch/xml?location=" + longLat + "&radius=" + radius + "&type=" + storeType + "&key=AIzaSyDd4VayFwaSkajfB2HtiFz71A70uSthM4A";

            string webContent = proxyWebToString.GetWebContent(url);

            XmlDocument xmldoc = new XmlDocument();

            xmldoc.LoadXml(webContent);

            XmlNodeList elemList = xmldoc.GetElementsByTagName("name");

            // List<string> storeNames = new List<string>();
            string result = "";

            for (int i = 0; i < elemList.Count; i++)
            {
                //  storeNames.Add(elemList[i].InnerXml);
                result += elemList[i].InnerXml + ", ";
            }
            return(result);
        }
示例#2
0
        /// <summary>
        /// Gives crime data in the area using zip code
        /// </summary>
        /// <param name="zipCode"></param>
        /// <returns></returns>
        public int[] getCrimeData(int zipCode)
        {
            //Zip, ViolentCrime,MurderAndManslaughter,ForcibleRape,Robbery,AggravatedAssault,PropertyCrime,Burglary,LarcenyTheft,MotorVehicleTheft
            int[] crimeDataRateReturn = new int[10];
            ServiceReferenceWebToString.ServiceClient proxyWebToString = new ServiceReferenceWebToString.ServiceClient();

            string geoDataServiceUrl = "https://azure.geodataservice.net/GeoDataService.svc/GetUSDemographics?includecrimedata=true&zipcode=" + zipCode;

            string      xmlInString = proxyWebToString.GetWebContent(geoDataServiceUrl);
            XmlDocument xmldoc      = new XmlDocument();

            xmldoc.LoadXml(xmlInString);

            List <XmlNodeList> elemList = new List <XmlNodeList>();

            elemList.Add(xmldoc.GetElementsByTagName("ZipCode"));
            elemList.Add(xmldoc.GetElementsByTagName("ViolentCrime"));
            elemList.Add(xmldoc.GetElementsByTagName("MurderAndManslaughter"));
            elemList.Add(xmldoc.GetElementsByTagName("ForcibleRape"));
            elemList.Add(xmldoc.GetElementsByTagName("Robbery"));
            elemList.Add(xmldoc.GetElementsByTagName("AggravatedAssault"));
            elemList.Add(xmldoc.GetElementsByTagName("PropertyCrime"));
            elemList.Add(xmldoc.GetElementsByTagName("Burglary"));
            elemList.Add(xmldoc.GetElementsByTagName("LarcenyTheft"));
            elemList.Add(xmldoc.GetElementsByTagName("MotorVehicleTheft"));

            for (int i = 0; i < crimeDataRateReturn.Length; i++)
            {
                crimeDataRateReturn[i] = Convert.ToInt32(elemList[i][0].InnerText);
            }
            return(crimeDataRateReturn);
        }
        /// <summary>
        /// Get latitude longitude info from the google api
        /// </summary>
        /// <param name="zip"></param>
        /// <returns></returns>
        public string getLatLong(string zip)
        {
            ServiceReferenceWebToString.ServiceClient proxyWebToString = new ServiceReferenceWebToString.ServiceClient();
            //Find latitude longitude using google api;
            string locationApi   = "https://maps.googleapis.com/maps/api/geocode/xml?address=" + zip;
            string xmlLocContent = proxyWebToString.GetWebContent(locationApi);

            XmlDocument xmlDocLocApi = new XmlDocument();

            xmlDocLocApi.LoadXml(xmlLocContent);
            XmlNodeList parentNode = xmlDocLocApi.GetElementsByTagName("location");
            string      latlng     = "";

            foreach (XmlNode childNode in parentNode)
            {
                string lat = childNode.SelectSingleNode("lat").InnerXml;
                string lng = childNode.SelectSingleNode("lng").InnerXml;
                latlng = lat + "," + lng;
            }
            return(latlng);
        }