nbsp; }
catch (Exception e)
{
info = "定位异常:" + e.Message;
return null;
}
return locationResult;
}
}
注:
(1).使用const常量来定义一个百度地图API的URL模板,方便后面的调用。
(2).TransToBaiduCoord函数是《C#的百度地图开发(二)转换JSON数据为相应的类》中将非百度坐标转换成百度坐标方法的封装。
(3).RequestUrl方法是《C#的百度地图开发(一)发起HTTP请求》所说的发起HTTP请求的封装。
(4).CoordLocationResult类的具体实现,请参看后面的代码。
- namespace MapApi.Baidu
- {
-
- [Serializable]
- public class CoordLocationResult
- {
- /// <summary>
- /// 状态
- /// </summary>
- public String status { get; set; }
-
- /// <summary>
- /// 结果
- /// </summary>
- public CoordLocationResult_Result result { get; set; }
- }
-
- #region CoordLocationResult_Result
- /// <summary>
- /// 定位结果
- /// </summary>
- [Serializable]
- public class CoordLocationResult_Result
- {
- /// <summary>
- /// 定位的经度与纬度
- /// </summary>
- public CoordLocationResult_Result_Location location { get; set; }
-
-