public LongLat QueryLocalSourceForLongLat(GoogleMapAddress add)
        {
            DataTable tb = Database.ExecutePCodeDatabaseQuery("SELECT longitude, latitude FROM tbl_postcodes WHERE postcode = '" + add.PostCode.Replace(" ", "") + "'");

            if (tb.Rows.Count != 1)
            {
                return(null);
            }

            return(new LongLat(tb.Rows[0][0].ToString(), tb.Rows[0][1].ToString(), add.PostCode));;
        }
        public LongLat QueryGoogleForLongLat(GoogleMapAddress add)
        {
            if (add == null)
            {
                throw new NullReferenceException("Invalid LongLat Object. Cannot Load PostCode");
            }

            if (add.PostCode.Split(' ').Count() > 2)
            {
                throw new Exception("Invalid Postcode Format");
            }

            LongLat retVal;

            try
            {
                retVal = QueryLocalSourceForLongLat(add);
            }
            catch (Exception e) { retVal = null; }


            if (retVal == null)
            {
                try
                {
                    LocationDetailsQuery qr = QueryGoogleForLocation(add.ToString());

                    if (qr.ErrorCode != null)
                    {
                        throw new Exception("Error Loading Location Details : " + qr.ErrorCode);
                    }
                    else if (qr.LongLat == null)
                    {
                        throw new PostCodeNotFoundException("Post Code Not Found For (" + add.PostCode + "," + add.Country + ")");
                    }

                    retVal = new LongLat(qr.LongLat.Split(',')[0], qr.LongLat.Split(',')[1], add.PostCode);
                }
                catch (Exception ex)
                {
                    throw new Exception("Failed to get location details");
                }
            }

            return(retVal);
        }
        public GoogleMapAddress QueryGoogleForAddress(LongLat ll)
        {
            //	if (Add == null)
            //	throw new NullReferenceException("Invalid Address Object. Cannot Load LongLat");

            GoogleMapAddress retVal;

            try
            {
                retVal = QueryLocalSourceForAddress(ll);
            }
            catch (Exception ex) { retVal = null; }

            if (retVal == null)
            {
                try
                {
                    LocationDetailsQuery qr = QueryGoogleForLocation(ll.ToString());


                    if (qr.ErrorCode != null)
                    {
                        throw new Exception("Error Loading Location Details : " + qr.ErrorCode);
                    }
                    else if (qr.PCode == null)
                    {
                        throw new PostCodeNotFoundException("Post Code Not Found For (" + ll.Longatude + ", " + ll.Latatude + ")");
                    }
                    else if (qr.Country == null)
                    {
                        throw new CountryNotFoundException("Country Not Found For (" + ll.Longatude + ", " + ll.Latatude + ")");
                    }

                    retVal = new GoogleMapAddress(qr.PCode, qr.Country);
                }
                catch (Exception ex)
                {
                    throw new Exception("Failed to get location details");
                }
            }

            return(retVal);
        }
 public GoogleMapLocation(LongLat longlat, string tag = null)
 {
     this.LongLat = longlat;
     this.Add     = QueryGoogleForAddress(longlat);
     this.Tag     = tag;
 }
 public GoogleMapLocation(GoogleMapAddress add, string tag = null)
 {
     this.Add     = add;
     this.LongLat = QueryGoogleForLongLat(@add);
     this.Tag     = tag;
 }
 public GoogleMapLocation(GoogleMapAddress add, LongLat longlat, string tag = null)
 {
     this.Add     = add;
     this.LongLat = longlat;
     this.Tag     = tag;
 }