Esempio n. 1
0
        //通过aoi获得位置信息表(2,4)
        public Ku_LocationEntity GetLocationByAOI(IRepository db, Ku_LocationEntity locationData, GeocodesItem geo, Regeocode regeo, Aois aoi, int isRegeo)
        {
            locationData = db.FindList <Ku_LocationEntity>(t => t.RegeoId == aoi.id).FirstOrDefault();
            if (locationData != null)
            {
                //有此坐标,个数+1
                locationData.Count += 1;
                locationData.Modify(locationData.Id);
                db.Update <Ku_LocationEntity>(locationData);
            }
            else
            {
                AddressComponent addressComponent = regeo.addressComponent;

                double wxLon = 0, wxLat = 0, bdLon = 0, bdLat = 0;
                GDAPI.getCoordinate(aoi.location, out wxLat, out wxLon, out bdLat, out bdLon);

                string typeCode, typeName;
                GetTypeNameByCode(aoi.type, out typeCode, out typeName);
                //无此坐标,插入pos_location表
                locationData = new Ku_LocationEntity()
                {
                    Address   = regeo.formatted_address,
                    Province  = addressComponent.province,
                    City      = addressComponent.city,
                    CityCode  = addressComponent.citycode,
                    District  = addressComponent.district,
                    AdCode    = addressComponent.adcode,
                    Township  = addressComponent.township,
                    Location  = aoi.location,
                    wxLon     = Convert.ToDecimal(wxLon),
                    wxLat     = Convert.ToDecimal(wxLat),
                    bdLon     = Convert.ToDecimal(bdLon),
                    bdLat     = Convert.ToDecimal(bdLat),
                    _Level    = geo.level,
                    IsRegeo   = isRegeo,
                    RegeoId   = aoi.id,
                    RegeoName = aoi.name,
                    Area      = aoi.area,//存在字母转换失败decimal“山东省临沂市平邑县地方镇九间棚”
                    TypeCode  = typeCode,
                    TypeName  = typeName,
                    Count     = 1
                };
                locationData.Create();
                db.Update <Ku_LocationEntity>(locationData);
            }
            return(locationData);
        }
Esempio n. 2
0
        //通过geo获得位置信息表(5)
        public Ku_LocationEntity GetLocationByGeo(IRepository db, Ku_LocationEntity locationData, GeocodesItem geo, int isRegeo)
        {
            //如果aoi取消
            locationData = db.FindList <Ku_LocationEntity>(t => t.Location == geo.location).FirstOrDefault();
            if (locationData != null)
            {
                locationData.Count += 1;
                locationData.Modify(locationData.Id);
                db.Update <Ku_LocationEntity>(locationData);
            }
            else
            {
                //添加POI
                double wxLon = 0, wxLat = 0, bdLon = 0, bdLat = 0;
                GDAPI.getCoordinate(geo.location, out wxLat, out wxLon, out bdLat, out bdLon);
                //无此坐标,插入pos_location表
                locationData = new Ku_LocationEntity()
                {
                    RegeoName = geo.formatted_address.Replace(geo.province, "").Replace(geo.city, "").Replace(geo.district, ""),
                    Address   = geo.formatted_address,
                    Province  = geo.province,
                    City      = geo.city,
                    CityCode  = geo.citycode,
                    District  = geo.district,
                    AdCode    = geo.adcode,
                    Township  = geo.township,
                    Location  = geo.location,
                    wxLon     = Convert.ToDecimal(wxLon),
                    wxLat     = Convert.ToDecimal(wxLat),
                    bdLon     = Convert.ToDecimal(bdLon),
                    bdLat     = Convert.ToDecimal(bdLat),
                    _Level    = geo.level,
                    IsRegeo   = 0,
                    Count     = 1
                };
                locationData.Create();
                db.Insert <Ku_LocationEntity>(locationData);
            }

            return(locationData);
        }
Esempio n. 3
0
        /// <summary>
        /// 根据地址通过高德地图api转成坐标,返回添加的坐标信息
        /// </summary>
        /// <param name="address">地址</param>
        public Ku_LocationEntity AddressToLocation(string address)
        {
            IRepository db = new RepositoryFactory().BaseRepository().BeginTrans();

            try
            {
                int isRegeo = 0;
                Ku_LocationEntity locationData = null;
                //根据地址转换,获取坐标
                GeocodesItem geo = GDAPI.AddressToGeo(address);
                //逆地理接口,通过坐标推出商圈
                Regeocode regeo = GDAPI.GetRegeoByGeo(geo.location);
                //1.先pois,distance=0的  2.再aoi=0的,
                if (regeo != null)
                {
                    List <PoisList> pois = regeo.pois;
                    List <Aois>     aois = regeo.aois;

                    //1.先pois,distance=0的
                    if (pois != null)
                    {
                        PoisList poi = pois[0];
                        if (poi.distance == "0")
                        {
                            isRegeo      = 1;
                            locationData = GetLocationByPOI(db, locationData, geo, regeo, poi, isRegeo);
                        }
                    }
                    //2.再aoi,distance=0的
                    if (isRegeo == 0)
                    {
                        if (aois != null)
                        {
                            Aois aoi = aois[0];//aoi根据距离排序的
                            if (aoi.distance == "0")
                            {
                                isRegeo      = 2;
                                locationData = GetLocationByAOI(db, locationData, geo, regeo, aoi, isRegeo);
                            }
                        }
                    }

                    if (isRegeo == 0)
                    {
                        //3.根据formatted_address再pois,
                        GeocodesItem geo2 = GDAPI.AddressToGeo(geo.formatted_address);
                        //如果二次转换为区县,市,未知,且与第一次转换的坐标一致,则放弃转换
                        if (geo2 != null && geo2.level != "区县" && geo2.level != "市" && geo2.level != "未知" && geo2.location != geo.location)
                        {
                            //逆地理接口,通过坐标推出商圈
                            Regeocode regeo2 = GDAPI.GetRegeoByGeo(geo2.location);
                            if (regeo2 != null)
                            {
                                List <PoisList> pois2 = regeo2.pois;
                                List <Aois>     aois2 = regeo2.aois;
                                if (pois2 != null)
                                {
                                    PoisList poi2 = pois2[0];
                                    if (poi2.distance == "0")
                                    {
                                        isRegeo      = 3;
                                        locationData = GetLocationByPOI(db, locationData, geo2, regeo2, poi2, isRegeo);
                                    }
                                }
                                //4.再aois
                                if (isRegeo == 0)
                                {
                                    if (aois2 != null)
                                    {
                                        Aois aoi2 = aois2[0];
                                        if (aoi2.distance == "0")
                                        {
                                            isRegeo      = 4;
                                            locationData = GetLocationByAOI(db, locationData, geo2, regeo2, aoi2, isRegeo);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                //0.无逆地理geo
                if (isRegeo == 0)
                {
                    locationData = GetLocationByGeo(db, locationData, geo, 0);
                }
                return(locationData);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }