예제 #1
0
        private void addGeocodeRequest(ref XLSType xLSType, string number, string street1, string street2, string city, string requestID)
        {
            RequestType requestType = xLSType.Request.Append();

            requestType.methodName.Value = "GeocodeRequest";

            GeocodeRequestType geocodeRequestType = requestType.GeocodeRequest.Append();
            AddressType        addressType        = geocodeRequestType.Address.Append();
            StreetAddressType  streetAddressType  = addressType.StreetAddress.Append();

            if (number != null)
            {
                BuildingLocatorType buildingLocatorType = streetAddressType.Building.Append();
                buildingLocatorType.number.Value = number;
            }

            StreetNameType streetNameType = streetAddressType.Street.Append();

            streetNameType.Value = street1;

            if (street2 != null)
            {
                StreetNameType streetNameType2 = streetAddressType.Street.Append();
                streetNameType2.Value = street2;
            }

            NamedPlaceType placeProvince = addressType.Place.Append();

            placeProvince.type.Value = "CountrySubdivision";
            placeProvince.Value      = city;
        }
        // toa do->dia chi
        public string doTestReverseGeocoderWithAddress(double kinhdo, double vido)
        {
            ReverseGeocoderTest reverseGeocoderTest = new ReverseGeocoderTest();
            XLSType             xLSTypeRequest      = reverseGeocoderTest.createXlsRequestTest(kinhdo, vido);
            XLSType             xLSTypeResponse     = RequestUtil.perform(xLSTypeRequest);

            if (xLSTypeResponse.Response.Exists)
            {
                ResponseType responseType = xLSTypeResponse.Response.First;
                ReverseGeocodeResponseType reverseGeocodeResponseType = responseType.ReverseGeocodeResponse.First;

                if (reverseGeocodeResponseType.ReverseGeocodedLocation.Exists)
                {
                    ReverseGeocodedLocationType reverseGeocodedLocationType = reverseGeocodeResponseType.ReverseGeocodedLocation.First;
                    PointType          pointType          = reverseGeocodedLocationType.Point.First;
                    DirectPositionType directPositionType = pointType.pos.First;
                    AddressType        addressType        = reverseGeocodedLocationType.Address.First;
                    StreetAddressType  streetAddressType  = addressType.StreetAddress.First;
                    //BuildingLocatorType buildingLocatorType = streetAddressType.Building.First;
                    string strStreetName   = "";
                    string buildingNumber  = "";
                    string strCommuneName  = "";
                    string strDistrictName = "";
                    string strProvinceName = "";
                    if (streetAddressType.Building.Exists)
                    {
                        BuildingLocatorType buildingLocatorType = streetAddressType.Building.First;
                        buildingNumber = buildingLocatorType.number.Value;
                    }
                    if (streetAddressType.Street.Exists)
                    {
                        StreetNameType streetNameType = streetAddressType.Street.First;
                        strStreetName = streetNameType.Value;
                    }

                    for (int j = 0; j < addressType.Place.Count; j++)
                    {
                        NamedPlaceType namedPlaceType = addressType.Place.At(j);
                        if (namedPlaceType.type.Value == "Municipality")
                        {
                            strCommuneName = namedPlaceType.Value;
                        }
                        else if (namedPlaceType.type.Value == "CountrySecondarySubdivision")
                        {
                            strDistrictName = namedPlaceType.Value;
                        }
                        else if (namedPlaceType.type.Value == "CountrySubdivision")
                        {
                            strProvinceName = namedPlaceType.Value;
                        }
                    }
                    if ((buildingNumber == "") && (strStreetName == "") && (strCommuneName == "") && (strDistrictName == "") && (strProvinceName == ""))
                    {
                        return("*");
                    }
                    //  string[] latlong = directPositionType.Value.Split(new string[] { " " } , StringSplitOptions.None);
                    string diachi;
                    if (buildingNumber == "0")
                    {
                        diachi = strStreetName + "," + strCommuneName + "," + strDistrictName + "," + strProvinceName;
                    }
                    else
                    {
                        diachi = buildingNumber + "," + strStreetName + "," + strCommuneName + "," + strDistrictName + "," + strProvinceName;
                    }
                    diachi = diachi.Replace(",,", ",");
                    return(diachi);
                }
                else
                {
                    return("*");
                }
            }
            else
            {
                return("*");
            }
        }
        /// <summary>
        /// lay nhieu ket qua
        /// </summary>
        /// <param name="xLSTypeResponse"></param>
        public ArrayList GetArrDiaChi(List <PointF> Data)
        {
            ReverseGeocoderTest reverseGeocoderTest = new ReverseGeocoderTest();
            XLSType             xLSTypeRequest      = reverseGeocoderTest.CreateRequest(Data);
            XLSType             xLSTypeResponse     = RequestUtil.perform(xLSTypeRequest);
            ArrayList           result = new ArrayList();

            if (xLSTypeResponse.Response.Exists)
            {
                string Duong = "", Xa = "", Huyen = "", Tinh = "";
                for (int i = 0; i < xLSTypeResponse.Response.Count; i++)
                {
                    ResponseType responseType = xLSTypeResponse.Response[i];
                    ReverseGeocodeResponseType reverseGeocodeResponseType = responseType.ReverseGeocodeResponse.First;

                    if (reverseGeocodeResponseType.ReverseGeocodedLocation.Exists)
                    {
                        ReverseGeocodedLocationType reverseGeocodedLocationType = reverseGeocodeResponseType.ReverseGeocodedLocation.First;
                        PointType          pointType          = reverseGeocodedLocationType.Point.First;
                        DirectPositionType directPositionType = pointType.pos.First;
                        AddressType        addressType        = reverseGeocodedLocationType.Address.First;
                        StreetAddressType  streetAddressType  = addressType.StreetAddress.First;


                        string strStreetName   = "";
                        string buildingNumber  = "";
                        string strCommuneName  = "";
                        string strDistrictName = "";
                        string strProvinceName = "";

                        if (streetAddressType.Building.Exists)
                        {
                            BuildingLocatorType buildingLocatorType = streetAddressType.Building.First;
                            buildingNumber = buildingLocatorType.number.Value.Trim();
                        }

                        if (streetAddressType.Street.Exists)
                        {
                            StreetNameType streetNameType = streetAddressType.Street.First;
                            strStreetName = streetNameType.Value.Trim();
                        }

                        for (int j = 0; j < addressType.Place.Count; j++)
                        {
                            NamedPlaceType namedPlaceType = addressType.Place.At(j);
                            if (namedPlaceType.type.Value == "Municipality")
                            {
                                strCommuneName = namedPlaceType.Value.Trim();
                            }
                            else if (namedPlaceType.type.Value == "CountrySecondarySubdivision")
                            {
                                strDistrictName = namedPlaceType.Value.Trim();
                            }
                            else if (namedPlaceType.type.Value == "CountrySubdivision")
                            {
                                strProvinceName = namedPlaceType.Value.Trim();
                            }
                        }

                        string[] latlong = directPositionType.Value.Split(new string[] { " " }, StringSplitOptions.None);

                        string KetQua = "";
                        strStreetName   = strStreetName.Trim();
                        strCommuneName  = strCommuneName.Trim();
                        strDistrictName = strDistrictName.Trim();
                        strProvinceName = strProvinceName.Trim();
                        if (strStreetName != "")
                        {
                            if (Duong != strStreetName)
                            {
                                KetQua += "Đường " + strStreetName + ", ";
                                if (Xa != strCommuneName)
                                {
                                    if (strCommuneName != "")
                                    {
                                        KetQua += strCommuneName + ", ";
                                    }
                                    if (Huyen != strDistrictName)
                                    {
                                        if (strDistrictName != "")
                                        {
                                            KetQua += strDistrictName + ", ";
                                        }
                                        if (Tinh != strProvinceName)
                                        {
                                            if (strProvinceName != "")
                                            {
                                                KetQua += strProvinceName;
                                            }
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (Xa != strCommuneName)
                                {
                                    if (strCommuneName != "")
                                    {
                                        KetQua += strCommuneName + ", ";
                                    }
                                    if (Huyen != strDistrictName)
                                    {
                                        if (strDistrictName != "")
                                        {
                                            KetQua += strDistrictName + ", ";
                                        }
                                        if (Tinh != strProvinceName)
                                        {
                                            if (strProvinceName != "")
                                            {
                                                KetQua += strProvinceName;
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    if (Huyen != strDistrictName)
                                    {
                                        if (strDistrictName != "")
                                        {
                                            KetQua += strDistrictName + ", ";
                                        }
                                        if (Tinh != strProvinceName)
                                        {
                                            if (strProvinceName != "")
                                            {
                                                KetQua += strProvinceName;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (Xa != strCommuneName)
                            {
                                KetQua += strCommuneName + ", ";
                                if (Huyen != strDistrictName)
                                {
                                    if (strDistrictName != "")
                                    {
                                        KetQua += strDistrictName + ", ";
                                    }
                                    if (Tinh != strProvinceName)
                                    {
                                        if (strProvinceName != "")
                                        {
                                            KetQua += strProvinceName;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (Huyen != strDistrictName)
                                {
                                    if (strDistrictName != "")
                                    {
                                        KetQua += strDistrictName + ", ";
                                    }
                                    if (Tinh != strProvinceName)
                                    {
                                        if (strProvinceName != "")
                                        {
                                            KetQua += strProvinceName;
                                        }
                                    }
                                }
                            }
                        }

                        /*
                         * if (i == (xLSTypeResponse.Response.Count - 1))
                         * {
                         * // if (KetQua == "")
                         * // {
                         *  KetQua = "";
                         *      if (strStreetName != "") KetQua += "Đường " + strStreetName + ", ";
                         *      if (strCommuneName != "") KetQua += strCommuneName + ", ";
                         *      if (strDistrictName != "") KetQua += strDistrictName + ", ";
                         *      if (strProvinceName != "") KetQua += strProvinceName;
                         * // }
                         * }
                         */
                        Duong = strStreetName;
                        Xa    = strCommuneName;
                        Huyen = strDistrictName;
                        Tinh  = strProvinceName;
                        if (KetQua != "")
                        {
                            if (KetQua.Substring(KetQua.Length - 1) == " ")
                            {
                                KetQua = KetQua.Remove(KetQua.Length - 2);
                            }
                        }
                        result.Add(KetQua);
                    }
                }
            }
            return(result);
        }
        public string doTestGeocoderByAddress(string numberBuild, string Street, string Province, string requestID)
        {
            GeocoderTest geocoderTest    = new GeocoderTest();
            XLSType      xLSTypeRequest  = geocoderTest.createXlsRequestTest(numberBuild, Street, null, Province, requestID);
            XLSType      xLSTypeResponse = RequestUtil.perform(xLSTypeRequest);

            if (xLSTypeResponse.Response.Exists)
            {
                ResponseType        responseType        = xLSTypeResponse.Response.First;
                GeocodeResponseType geocodeResponseType = responseType.GeocodeResponse.First;

                if (geocodeResponseType.GeocodeResponseList.Exists)
                {
                    GeocodeResponseListType geocodeResponseListType = geocodeResponseType.GeocodeResponseList.First;
                    if (geocodeResponseListType.GeocodedAddress.Exists)
                    {
                        GeocodedAddressType geocodedAddressType = geocodeResponseListType.GeocodedAddress.First;
                        PointType           pointType           = geocodedAddressType.Point.First;
                        DirectPositionType  directPositionType  = pointType.pos.First;
                        AddressType         addressType         = geocodedAddressType.Address.First;
                        StreetAddressType   streetAddressType   = addressType.StreetAddress.First;
                        BuildingLocatorType buildingLocatorType = streetAddressType.Building.First;

                        string buildingNumber  = buildingLocatorType.number.Value;
                        string strCommuneName  = "";
                        string strDistrictName = "";
                        string strProvinceName = "";
                        string strStreetName   = "";



                        if (streetAddressType.Street.Exists)
                        {
                            StreetNameType streetNameType = streetAddressType.Street.First;
                            strStreetName = streetNameType.Value;
                        }

                        foreach (NamedPlaceType namedPlaceType in addressType.Place)
                        {
                            if (namedPlaceType.type.Value == "Municipality")
                            {
                                strCommuneName = namedPlaceType.Value;
                            }
                            else if (namedPlaceType.type.Value == "CountrySecondarySubdivision")
                            {
                                strDistrictName = namedPlaceType.Value;
                            }
                            else if (namedPlaceType.type.Value == "CountrySubdivision")
                            {
                                strProvinceName = namedPlaceType.Value;
                            }
                        }
                        // string[] latlong = directPositionType.Value.Split(new string[] { " " } , StringSplitOptions.None);
                        return(directPositionType.Value.ToString());
                    }
                    else
                    {
                        return("*");
                    }
                }
                else
                {
                    return("*");
                }
            }
            else
            {
                return("*");
            }
        }