Beispiel #1
0
        public ResponseData Geocode(RequestData requestData)
        {
            var resp = new ResponseData();

            string url = "http://geocode-maps.yandex.ru/1.x/?geocode={0}&lang=tr-TR";

            WebResponse response = null;
            try
            {
                url = string.Format(url, requestData.Address);
                var request = (HttpWebRequest)WebRequest.Create(url);
                request.Method = "GET";
                response = request.GetResponse();

                using (var reader = new StreamReader(response.GetResponseStream()))
                {
                    resp.Data = reader.ReadToEnd();
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                if (response != null)
                {
                    response.Close();
                }
            }

            return resp;
        }
Beispiel #2
0
        public ResponseData Geocode(RequestData requestData)
        {
            var resp = new ResponseData();

            string url = "https://maps.googleapis.com/maps/api/geocode/xml?address={0}&key={1}";

            WebResponse response = null;

            try
            {
                url = string.Format(url, requestData.Address, GoogleGeocodeApiKey);
                var request = (HttpWebRequest)WebRequest.Create(url);
                request.Method = "GET";
                response = request.GetResponse();

                using (var reader = new StreamReader(response.GetResponseStream()))
                {
                    resp.Data = reader.ReadToEnd();
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                if (response != null)
                {
                    response.Close();
                }
            }

            return resp;
        }
Beispiel #3
0
        public List<GoogleResult> GeocodeAndParse(RequestData requestData)
        {
            ResponseData responseData = Geocode(requestData);
            XmlDocument xml = Common.GetXmlDocumentFromXmlString(responseData.Data);
            decimal geocodeCount = GetGoogleFoundedGeocodeCount(xml);

            if (geocodeCount == 0)
            {
                return new List<GoogleResult>();
            }

            List<GoogleResult> resultList = GoogleGeocodeResult(xml);
            return resultList;
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            GoogleGeocoder googleGeocoder = new GoogleGeocoder();
            YandexGeocoder yandexGeocoder = new YandexGeocoder();

            RequestData request = new RequestData()
            {
                Address = "inönü mahallesi atatürk caddesi birlik apt. no:55 daire 7 istanbul ataşehir türkiye"
            };

            ResponseData googleResult = googleGeocoder.Geocode(request);

            List<GoogleResult> googleGeocodeResultList = googleGeocoder.GeocodeAndParse(request);

            ResponseData yandexResult = yandexGeocoder.Geocode(request);

            List<YandexResult> yandexGeocodeResultList = yandexGeocoder.GeocodeAndParse(request);
        }
Beispiel #5
0
        private void button1_Click(object sender, EventArgs e)
        {
            List<SAMPLEADDRESS> samples = geocoderService.GetSampleaddresss();

            Stopwatch timer = new Stopwatch();

            foreach (var item in samples)
            {
                bool checkIfExist = geocoderService.CheckIfExist(item);

                if (checkIfExist)
                {
                    continue;
                }

                SAMPLEADDRESSRESULT result = new SAMPLEADDRESSRESULT();

                RequestData request = new RequestData();
                request.Address = item.ADDRESS + " " + item.CITY + " " + item.TOWN;
                timer.Reset();
                timer.Start();
                List<YandexResult> yandexResults = yandexGeocoder.GeocodeAndParse(request);
                timer.Stop();

                if (yandexResults.Count == 1)
                {
                    string[] coordinates = yandexResults[0].Position.Split(' ');
                    string xCoor = coordinates[0];
                    string yCoor = coordinates[1];

                    result.XCOORYANDEX = xCoor;
                    result.YCOORYANDEX = yCoor;
                    result.YANDEXTIME = timer.Elapsed.ToString();
                }
                timer.Reset();

                timer.Start();
                List<GoogleResult> googleResults = googleGeocoder.GeocodeAndParse(request);
                timer.Stop();

                if (googleResults.Count == 1)
                {
                    string xCoor = googleResults[0].Longtitute;
                    string yCoor = googleResults[0].Latitute;

                    result.XCOORGOOGLE = xCoor;
                    result.YCOORGOOGLE = yCoor;
                    result.GOOGLETIME = timer.Elapsed.ToString();
                }

                timer.Reset();

                timer.Start();
                AddressLevel addressLevel = Geocode(request.Address);
                timer.Stop();

                if (addressLevel.XCoor != string.Empty || addressLevel.XCoor != "0")
                {
                    string xCoor = addressLevel.XCoor;
                    string yCoor = addressLevel.YCoor;

                    result.XCOORMY = xCoor;
                    result.YCOORMY = yCoor;
                    result.MYTIME = timer.Elapsed.ToString();
                }

                result.ID = item.ID;
                try
                {
                    geocoderService.InsertSampleAddressResult(result);
                }
                catch
                {
                    continue;
                }
            }
        }