Exemplo n.º 1
0
        public GoogleMapAddress QueryLocalSourceForAddress(LongLat ll)
        {
            DataTable tb = Database.ExecutePCodeDatabaseQuery("SELECT postcode FROM tbl_postcodes WHERE latitude = " + ll.Latatude.ToString() + " and longitude = " + ll.Longatude.ToString());

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

            string pcode = tb.Rows[0][0].ToString();

            pcode = pcode.Insert(pcode.Length - 3, " ");

            return(new GoogleMapAddress(pcode, "UK"));
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
 public GoogleMapLocation(LongLat longlat, string tag = null)
 {
     this.LongLat = longlat;
     this.Add     = QueryGoogleForAddress(longlat);
     this.Tag     = tag;
 }
Exemplo n.º 5
0
 public GoogleMapLocation(GoogleMapAddress add, string tag = null)
 {
     this.Add     = add;
     this.LongLat = QueryGoogleForLongLat(@add);
     this.Tag     = tag;
 }
Exemplo n.º 6
0
 public GoogleMapLocation(GoogleMapAddress add, LongLat longlat, string tag = null)
 {
     this.Add     = add;
     this.LongLat = longlat;
     this.Tag     = tag;
 }