Exemplo n.º 1
0
 private string BuildAddressString(Address _address)
 {
     if (_address.FullAddressString == null)
         return _address.Country + " " + _address.State + " " + _address.City + " " + _address.Street + " " + _address.Building;
     else
     {
         return _address.FullAddressString;
     }
 }
Exemplo n.º 2
0
        public Address GetGpsAddress(string countryName, int countryId, string Lat, string Long)
        {
            string url = "http://maps.google.com/maps/api/geocode/json?latlng=" + Lat + "," + Long + "&sensor=false";
            var request = (HttpWebRequest)HttpWebRequest.Create(url);
            request.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate");
            request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
            DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(GeoResponse));
            GeoResponse r = null;
            try
            {
                r = (GeoResponse)serializer.ReadObject(request.GetResponse().GetResponseStream());
            }
            catch (Exception ee)
            {
                string str = ee.Message;
            }

            Address _location = new Address();
            if (r.Status == "OK")
            {
                _location.SearchResult = (int)LocationSearchResultEnum.Found;
                var v = r.Results.ToList();
                GeoResponse.CResult rr;
                //rr = r.Results.Where(c => c.AddressComponents.Any(x => c.Type.Contains("street_number"))).FirstOrDefault();
                rr =
                    r.Results.Where(c => c.AddressComponents.Any(x => x.Type.Contains("street_number"))).FirstOrDefault();

                if (rr == null)
                {
                    rr = r.Results.Where(c => c.AddressComponents.Any(x => x.Type.Contains("route"))).FirstOrDefault();
                }
                if (rr == null)
                    _location.SearchResult = (int)LocationSearchResultEnum.NotFound;
                else
                {
                    _location.LocationType = rr.Geometry.LocationType;
                    string sNum = "", sStreet = "", sCity = "", sState = "";
                    GeoResponse.CResult.GeocodeAddressComponent[] addrc = rr.AddressComponents;
                    List<GoogleAddressPartsToDB> addrDbProps = GetCountryGoogleProps(Convert.ToInt32(countryId));
                    if ((addrDbProps != null) && (addrDbProps.Count > 0))
                    {
                        List<GeoResponse.CResult.GeocodeAddressComponent> responseComponents = addrc.ToList();
                        sState = GetAddressPartString(2, responseComponents, addrDbProps);
                        sCity = GetAddressPartString(3, responseComponents, addrDbProps);
                        sStreet = GetAddressPartString(4, responseComponents, addrDbProps);
                        sNum = GetAddressPartString(5, responseComponents, addrDbProps);

                    }
                    else
                    {
                        for (int i = 0; i < addrc.Length; i++)
                        {
                            string sprop = addrc[i].Type[0];
                            if (sprop == "street_number")
                                sNum = addrc[i].ShortName;
                            if (sprop == "route")
                                sStreet = addrc[i].ShortName;
                            if (sprop == "administrative_area_level_1")
                            {
                                sState = addrc[i].ShortName;

                            }
                            if (sprop == "locality")
                                sCity = addrc[i].ShortName;
                        }

                    } //if ((addrDbProps != null) && (addrDbProps.Count > 0))

                    _location.Building = sNum;
                    _location.Street = sStreet;
                    _location.City = sCity;
                    _location.State = sState;
                    _location.Country = countryName;
                    _location.FullAddressString = countryName;
                    if (sState.Length > 0)
                    {
                        _location.FullAddressString += " ";
                        _location.FullAddressString += sState;
                    }
                    _location.FullAddressString = _location.FullAddressString + " " + sCity + " " + sStreet;
                    if (sNum.Length > 0)
                    {
                        _location.FullAddressString += " ";
                        _location.FullAddressString += sNum;
                    }
                }

            }
            else if (r.Status == "ZERO_RESULTS")
            {
                _location.SearchResult = (int)LocationSearchResultEnum.NotFound;
            }
            else if (r.Status == "REQUEST_DENIED")
            {
                _location.SearchResult = (int)LocationSearchResultEnum.RequestDenied;
            }
            else if (r.Status == "OVER_QUERY_LIMIT")
            {
                _location.SearchResult = (int)LocationSearchResultEnum.OverProcessCountLimit;
            }
            else
                _location.SearchResult = (int)LocationSearchResultEnum.Error;

            return _location;
        }
Exemplo n.º 3
0
        public GoogleSearchAddressResponse GetLocationFullString(int CountryId, string Country, string strAddress)
        {
            GoogleSearchAddressResponse location = new GoogleSearchAddressResponse();
            List<Address> points = new List<Address>();
            GeoResponse r = GetGoogleLocation(strAddress);
            if (r != null)
            {
                if ((r.Status == "OK"))
                {
                    location.SearchResult = (int)LocationSearchResultEnum.Found;
                    var v = r.Results.ToList();
                    foreach (var rr in v)
                    {

                        Address s_addr = new Address();
                        GeoResponse.CResult.CGeometry.CLocation loc = rr.Geometry.Location;
                        s_addr.Latitude = loc.Lat;
                        s_addr.Longitude = loc.Lng;
                        s_addr.FullAddressString = rr.formatted_address;
                        s_addr.LocationType = rr.Geometry.LocationType;
                        string sNum = "", sStreet = "", sCity = "", sState = "";
                        GeoResponse.CResult.GeocodeAddressComponent[] addrc = rr.AddressComponents;
                        List<GoogleAddressPartsToDB> addrDbProps = GetCountryGoogleProps(CountryId);
                        if ((addrDbProps != null) && (addrDbProps.Count > 0))
                        {
                            List<GeoResponse.CResult.GeocodeAddressComponent> responseComponents = addrc.ToList();
                            sState = GetAddressPartString(2, responseComponents, addrDbProps);
                            sCity = GetAddressPartString(3, responseComponents, addrDbProps);
                            sStreet = GetAddressPartString(4, responseComponents, addrDbProps);
                            sNum = GetAddressPartString(5, responseComponents, addrDbProps);
                            s_addr.Building = sNum;
                            s_addr.Street = sStreet;
                            s_addr.City = sCity;
                            s_addr.State = sState;
                            s_addr.Country = Country;

                        }
                        else
                        {
                            for (int i = 0; i < addrc.Length; i++)
                            {
                                string sprop = addrc[i].Type[0];
                                if (sprop == "street_number")
                                    sNum = addrc[i].ShortName;
                                if (sprop == "route")
                                    sStreet = addrc[i].ShortName;
                                if (sprop == "administrative_area_level_1")
                                    sState = addrc[i].ShortName;
                                if (sprop == "locality")
                                    sCity = addrc[i].ShortName;
                            }
                        }
                        s_addr.Building = sNum;
                        s_addr.Street = sStreet;
                        s_addr.City = sCity;
                        s_addr.State = sState;
                        s_addr.Country = Country;
                        points.Add(s_addr);
                    }

                }

                else if (r.Status == "ZERO_RESULTS")
                {
                    location.SearchResult = (int)LocationSearchResultEnum.NotFound;
                }
                else if (r.Status == "REQUEST_DENIED")
                {
                    location.SearchResult = (int)LocationSearchResultEnum.RequestDenied;
                }
                else if (r.Status == "OVER_QUERY_LIMIT")
                {
                    location.SearchResult = (int)LocationSearchResultEnum.OverProcessCountLimit;
                }
                else
                    location.SearchResult = (int)LocationSearchResultEnum.Error;
            }

            location.ServiceResponseAddresses = points;

            return location;
        }
Exemplo n.º 4
0
        public JsonResult insertAddress(int stateID, int cityID, int streetID, string buildingNumber, string entry, string zipCode, string state, string city, string street)
        {
            try
            {
                int countryID = SessionManagement.Country;

                var objBuilding = _facory.GetChangeBuildingCode1(countryID, stateID, cityID, streetID, buildingNumber, entry, zipCode);

                if (objBuilding == null)//not found building code
                {
                    GoogleDomainService objGoogleDomainService = new GoogleDomainService();
                    var objAddress = new Address
                    {
                        CountryId = countryID,
                        Country = SessionManagement.CountryDesc,
                        State = state,
                        City = city,
                        Street = street,
                        Building = buildingNumber
                    };

                    var result = objGoogleDomainService.GetLocation(objAddress);
                    return new JsonResult { Data = new { IsSuccess = true, IsOpenMap = true, Result = result }, JsonRequestBehavior = JsonRequestBehavior.AllowGet };

                }
                else
                {
                    return new JsonResult { Data = new { IsSuccess = true, IsOpenMap = false, BuildingCode = objBuilding.BuildingCode, BuildingLat = objBuilding.Lat, BuildingLong = objBuilding.Long }, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
                }

            }
            catch (Exception ex)
            {

                return new JsonResult { Data = new { IsSuccess = false, IsOpenMap = false, ErrorMessage = ex.Message }, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
            }
            //using (ISEEEntities context = new ISEEEntities())
            //{
            //    GoogleDomainService objGoogleDomainService = new GoogleDomainService();

            //    int FactoryId = ISEE.Common.SessionManegment.SessionManagement.FactoryID;
            //    int countryID = ISEE.Common.SessionManegment.SessionManagement.Country;

            //    var a = new Address
            //    {
            //        CountryId = countryID,
            //        Country = ISEE.Common.SessionManegment.SessionManagement.CountryDesc,
            //        State = stateID,
            //        City = cityID,
            //        Street = streetID,
            //        Building = buildingNumber
            //    };

            //    var result = objGoogleDomainService.GetLocation(a);

            //var result = context.Buildings.Where(x => x.CountryCode == countryID
            //    && x.StateCode == (stateID == null ? x.StateCode : stateID)
            //    && x.StreetCode == (streetID == null ? x.StreetCode : streetID)
            //    && x.CityCode == (cityID == null ? x.CityCode : cityID)).Select(s => new { CountryName = s.Street.City.State.Country.CountryDesc, StateName = s.Street.City.State.StateDesc, CityName = s.Street.City.CityDesc, StreetName = s.Street.StreetDesc, BuldingNumber = s.Number, Lat = s.Lat, Long = s.Long, Number = s.Number }).ToList();
        }