예제 #1
0
        public IGeoCodeResult GetCoordinates(string search)
        {
            if (providers.Count == 0)
            {
                SetupDefaults();
            }

            IGeoCodeResult gResult = new GeoCodeResult();

            foreach (IGeoProvider provider in providers)
            {
                try
                {
                    gResult = provider.GetCoordinates(search);
                } catch (Exception ex)
                {
                    throw (ex);
                }

                if (gResult.HasValue)
                {
                    break;
                }
            }

            return(gResult);
        }
예제 #2
0
파일: GeoCoder.cs 프로젝트: sbosell/geocode
        public IGeoCodeResult GetCoordinates(string search)
        {
            if (providers.Count == 0) SetupDefaults();

            IGeoCodeResult gResult = new GeoCodeResult();

            foreach (IGeoProvider provider in providers)
            {
                try
                {
                    gResult = provider.GetCoordinates(search);
                } catch (Exception ex)
                {
                    throw (ex);
                }

                if (gResult.HasValue)
                {
                    break;
                }

            }

            return gResult;
        }
예제 #3
0
        static void Main(string[] args)
        {
            //DEFAULT, GoogleMaps

               // GeoCoder gc = new GeoCoder();
               // IGeoCodeResult Target = new GeoCodeResult();
            //Target = g.GetCoordinates("Austin, TX");  // defaults to Google's GMap Service

            //BING MAPS

            GeoCoder gc = new GeoCoder();
            BingMapConfig bmc = new BingMapConfig();
            bmc.Key = "AjgNhLFwXI1zRKHwTyZYQSXQZwTlWdHrjSZ6DD-Pcp6rihIEeIoG7ywMGmb_TiRs";
            gc.AddProvider(new BingMap(bmc));
            IGeoCodeResult Target = new GeoCodeResult();

            //MAP QUEST

            //GeoCoder gc = new GeoCoder();
            //MapQuestConfig mqc = new MapQuestConfig();
            //mqc.Key = "Fmjtd%7Cluubn1ut2d%2Cbw%3Do5-90b09y";
            //gc.AddProvider(new MapQuestMap(mqc));
            //IGeoCodeResult Target = new GeoCodeResult();
            //Target = gc.GetCoordinates("Abstatt");

            //OSM

            //IGeoCodeResult Target = new GeoCodeResult();
            //GeoCoder gc = new GeoCoder();
            //gc.AddProvider(new OpenStreetMap());
            //Target = gc.GetCoordinates("Austin, TX");

            //CLOUD MATE

            //GeoCoder gc = new GeoCoder();
            //CloudMadeConfig cmc = new CloudMadeConfig();
            //cmc.Key = "66ac5b1df21848ecafa38a53d92dabd1";

            //gc.AddProvider(new CloudMade(cmc));
            //IGeoCodeResult Target = new GeoCodeResult();
            //Target = gc.GetCoordinates("Austin, TX");

            Target = gc.GetCoordinates("");
            double lat;
            double lng;
            JObject response = (JObject)JsonConvert.DeserializeObject(Target.response);
            System.Console.WriteLine("JSON Response: " + response.ToString());
            System.Console.WriteLine(response.ToString());
            if (Target.HasValue)
            {
                lat = Target.Latitude;
                lng = Target.Longitude;
                System.Console.WriteLine("latitude: " + lat + "--- longitude: " + lng);
                System.Console.WriteLine("country" + Target.Locations.First().Country);

            }
            Console.ReadLine();
        }
예제 #4
0
        // GET api/<controller>
        public IGeoCodeResult Query(GeoQuery q)
        {
            string key = string.Empty;
            string query = string.Empty;
            string provider = "Google";
            IGeoProviderConfig config;
            IGeoProvider GeoProvider = null;

            IGeoCodeResult result = new GeoCodeResult();

            if (!String.IsNullOrEmpty(q.Query) && !String.IsNullOrEmpty(q.Providers))
            {
                query = q.Query;
                // we have a search
                provider = q.Providers.Replace("KEY", "");
                if (q.Providers.Contains("KEY"))
                {
                    key = q.Key;
                }

                switch (provider)
                {
                    case "Google":
                        config = new GoogleGmapConfig();
                        GeoProvider = new GoogleGmap(config);
                        break;
                    case "Bing":
                        config = new BingMapConfig().SetKey(key);
                        GeoProvider = new BingMap(config);
                        break;
                    case "MapQuest":
                        config = new MapQuestConfig().SetKey(key);
                        GeoProvider = new MapQuestMap(config);
                        break;
                    case "Open Streets":
                        config = new OpenStreetMapConfig().SetUserAgent("your email here yo");
                        GeoProvider = new OpenStreetMap(config);
                        break;
                    case "YahooPlaces":
                        config = new YahooPlaceFinderConfig().SetKey(key);
                        GeoProvider = new YahooPlaceFinder(config);
                        break;
                    case "CloudMade":
                        config = new CloudMadeConfig().SetKey(key);
                        GeoProvider = new CloudMade(config);
                        break;

                }

                GeoProvider = GeoProvider != null ? GeoProvider : new GoogleGmap();

                GeoCoder gc = new GeoCoder(GeoProvider);

                result = gc.GetCoordinates(query);

            }
            return result;
        }
예제 #5
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);
        }
예제 #6
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);
        }
예제 #7
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);
        }
예제 #8
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);
        }
예제 #9
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);
        }
예제 #10
0
        public void BingMapTestAlternateUrl()
        {
            BingMapConfig bmc = new BingMapConfig()
                .SetKey(BingKey)
                .SetUrl("http://dev.virtualearth.net/REST/v1/Locations/?maxResults=1")
                .SetSearchQuery("q")
                .SetKeyQuery("key");

            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);
        }
예제 #11
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);
        }
예제 #12
0
        public void GoogleGmapAmbiguous()
        {
            GoogleGmap g = new GoogleGmap();

            IGeoCodeResult Target = new GeoCodeResult();

            Target = g.GetCoordinates("Paris");
            Assert.IsTrue(Target.Count>0);
        }
예제 #13
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);
        }
예제 #14
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);
        }
예제 #15
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);
        }
예제 #16
0
        public void GeoCoderFirstFails()
        {
            var Expected = new {
               Latitude = 30.1968545,
               Longitude = -97.5975533560703
            };

            IGeoCodeResult Target = new GeoCodeResult();

            GoogleGmapConfig gmc =
                new GoogleGmapConfig()
                    .SetUrl("http://madps.googleapis.com/maps/api/geocode/json?address={0}&sensor=true");

            GeoCoder gc = new GeoCoder()
                .AddProvider(new GoogleGmap(gmc))
                .AddProvider(new OpenStreetMap());

            Target = gc.GetCoordinates("Austin, TX");
            Assert.AreEqual(Expected.Latitude, Target.Latitude);
            Assert.AreEqual(Expected.Longitude, Target.Longitude);
        }
예제 #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);
        }
예제 #18
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);
        }
예제 #19
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
        }
예제 #20
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);
        }