コード例 #1
0
ファイル: Ku_LocationService.cs プロジェクト: zhangvs/Map
        //通过poi获得位置信息表(1,3)
        public Ku_LocationEntity GetLocationByPOI(IRepository db, Ku_LocationEntity locationData, GeocodesItem geo, Regeocode regeo, PoisList item, int isRegeo)
        {
            locationData = db.FindList <Ku_LocationEntity>(t => t.RegeoId == item.id).FirstOrDefault();
            if (locationData != null)
            {
                //有此坐标,个数+1
                locationData.Count += 1;
                locationData.Modify(locationData.Id);
                db.Update <Ku_LocationEntity>(locationData);
            }
            else
            {
                AddressComponent addressComponent  = regeo.addressComponent;
                string           formatted_address = regeo.formatted_address;

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

                string typeCode, typeName;
                GetTypeCodeByName(item.type, out typeCode, out typeName);
                //无此坐标,插入pos_location表
                locationData = new Ku_LocationEntity()
                {
                    Address   = item.address,
                    Province  = addressComponent.province,
                    City      = addressComponent.city,
                    CityCode  = addressComponent.citycode,
                    District  = addressComponent.district,
                    AdCode    = addressComponent.adcode,
                    Township  = addressComponent.township,
                    Location  = item.location,
                    wxLon     = Convert.ToDecimal(wxLon),
                    wxLat     = Convert.ToDecimal(wxLat),
                    bdLon     = Convert.ToDecimal(bdLon),
                    bdLat     = Convert.ToDecimal(bdLat),
                    _Level    = geo.level,
                    IsRegeo   = isRegeo,
                    RegeoId   = item.id,
                    RegeoName = item.name,
                    TypeCode  = typeCode,
                    TypeName  = typeName,
                    Count     = 1
                };
                locationData.Create();
                db.Insert <Ku_LocationEntity>(locationData);
            }
            return(locationData);
        }
コード例 #2
0
ファイル: Ku_LocationService.cs プロジェクト: zhangvs/Map
        /// <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);
            }
        }