public void ShouldReturnEmptyResultWithFakeKeyProvided()
 {
     var geocoder = new BingGeocoderClient("blah");
      var result = geocoder.Geocode("blah");
      Assert.AreEqual(result.Confidence, "No results");
      Assert.IsNotNull(result.ErrorMessage);
 }
        public ActionResult MapInformation()
        {
            var zipcodes = GardenRepository.All().Select(c => c.ZipCode).Where(z => z.Length > 4 && z.StartsWith("84")).ToList();
            var distinctZipCodes = zipcodes.Distinct();
            var geocoder = new BingGeocoderClient("AlqLYGnwzgowzmozmv0Wy4TtXkoBLkAMAYKXu106gbu6O3MWj9jVpnHKVS20Obj-");

            var list = new List<ZipCodeData>();
            foreach (var zipcode in zipcodes.Distinct())
            {
                if (Cache[zipcode] == null)
                {
                    var result = geocoder.Geocode(zipcode);
                    if (!string.IsNullOrEmpty(result.Longitude) && !string.IsNullOrEmpty(result.Latitude))
                        Cache.Insert(zipcode, new ZipCodeData(zipcode, float.Parse(result.Latitude), float.Parse(result.Longitude), zipcodes.Count(z => z.Equals(zipcode))));
                }
                else
                {
                    var zipCodeData = (ZipCodeData)Cache[zipcode];
                    var zipCodeCount = zipcodes.Count(z => z == zipcode);
                    if (zipCodeData.Count != zipCodeCount)
                    {
                        zipCodeData.Count = zipCodeCount;
                        Cache[zipcode] = zipCodeData;
                    }
                }

                list.Add((ZipCodeData)Cache[zipcode]);
            }

            return Json(new
                            {
                                Result = list
                            }, JsonRequestBehavior.AllowGet);
        }
 public void ShouldReturnValidResultWithRealKeyProvidedAndRealQuery()
 {
     var geocoder = new BingGeocoderClient(Key);
      var result = geocoder.Geocode("ATL");
      Assert.AreNotEqual(result.Confidence, "No results");
      Assert.IsNotNull(result.Latitude);
      Assert.IsNotNull(result.Longitude);
      Assert.IsNull(result.ErrorMessage);
 }
 public void ShouldReturnValidResultWithRealKeyProvidedAndRealAddress()
 {
     var geocoder = new BingGeocoderClient(Key);
      var result = geocoder.Geocode("1230 Peachtree St", "Atlanta", "GA", "30309");
      Assert.AreNotEqual(result.Confidence, "No results");
      Assert.IsNotNull(result.Latitude);
      Assert.IsNotNull(result.Longitude);
      Assert.IsNull(result.ErrorMessage);
 }
 public void ShouldReturnEmptyResultWithRealKeyProvidedAndFakeAddress()
 {
     var geocoder = new BingGeocoderClient(Key);
      var result = geocoder.Geocode("123 Blah Blah", "Test", "Test", "Test");
      Assert.AreNotEqual(result.Confidence, "No results");
      Assert.IsNotNull(result.Latitude);
      Assert.IsNotNull(result.Longitude);
      Assert.IsNull(result.ErrorMessage);
 }
Пример #6
0
    public static BingGeocoderResult GeoCodeAddress(string address)
    {
        string APIKey = "";
            if (APIKey != "") {
                var result = (BingGeocoderResult)HttpContext.Current.Cache.Get("GEO:" + address);

                if(result == null){
                    var geocoder = new BingGeocoderClient(APIKey);
                    result = geocoder.Geocode(address + " Sweden");
                    HttpContext.Current.Cache.Insert("GEO:" + address, result, null, DateTime.MaxValue,TimeSpan.FromDays(300));
                }

                return result;
            }
            else{
                return null;
            }
    }