Ejemplo n.º 1
0
        /// <summary>
        /// 转换高德地理坐标为百度的地图坐标
        /// </summary>
        /// <returns></returns>
        public static IPPoint ConvertFromAmapGps(BaiduMapClient baiduClient, decimal longitude, decimal latitude)
        {
            var model = new CoordTransfModel
            {
                Coords = string.Format("{0},{1}", longitude, latitude),
                From   = CoordTransfModel.From_AMAP
            };
            var req  = new CoordTransformRequest(model);
            var resp = baiduClient.Execute(req);

            if (resp.Result != null && resp.Result.Count > 0)
            {
                return(resp.Result[0]);
            }
            return(null);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 根据地址获取百度的地址信息(包含坐标、城市省份地区地址、百度Poi),注意,本接口将通过网络访问百度服务器;
        /// </summary>
        /// <param name="client"></param>
        /// <param name="address"></param>
        /// <returns></returns>
        public static ReGeoDetailItem GetAddressInfo(BaiduMapClient client, string address)
        {
            address = address.Replace("(", "").Replace(")", "").Replace(" ", "");
            var geoCoderModel = new GeoCoderModel
            {
                Address = address
            };
            var req = new GeoCoderRequest(geoCoderModel);
            var res = client.Execute(req);

            if (res.Result == null || res.Result.Location == null)
            {
                return(null); //返回 null;
            }
            return(GetAddressInfo(client, res.Result.Location.Lng, res.Result.Location.Lat));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 根据坐标解析地址;
        /// </summary>
        /// <param name="client"></param>
        /// <param name="lng"></param>
        /// <param name="lat"></param>
        /// <returns></returns>
        public static ReGeoDetailItem GetAddressInfo(BaiduMapClient client, double?lng, double?lat)
        {
            IPPoint baiduGps = new IPPoint {
                X = lng, Y = lat
            };
            var model = new ReGeoCoderModel
            {
                location = string.Format("{0},{1}", baiduGps.Y, baiduGps.X),
                pois     = 1,
                radius   = 200
            };
            var request = new ReGeoCoderRequest(model);
            ReGeoCoderResponse result = client.Execute(request);

            if (result.Result == null)
            {
                return(null);
            }
            var regeo = result.Result;

            return(regeo);
        }
Ejemplo n.º 4
0
 public void TestInitiate()
 {
     // the follow key is only for test;
     BaiduMapConfig.AddBaiduMapConfig("Ar0P3ZtGzAbdDRvacMWUVvvHtjtftoWI", "iLY3xsGGI1SQ7kHjH9TbGAclgv9TI3FF");
     client = BaiduMapConfig.GetClient();
 }