1、创建基础参数类
public static class BaiduErrorMessages
{
public const string NotKey = "密钥不存在";
public const string LackParam = "缺少必要请求参数";
}
</div>
2、定义API错误信息与产品信息
public enum Status
{
/// <summary>
/// 正常
/// </summary>
Ok = 0,
/// <summary>
/// 请求参数非法
/// </summary>
ParameterInvalid = 2,
/// <summary>
/// 权限校验失败
/// </summary>
VerifyFailure = 3,
/// <summary>
/// 配额校验失败
/// </summary>
QuotaFailure = 4,
/// <summary>
/// 不存在或者非法
/// </summary>
AkFailure = 5,
/// <summary>
/// Transform 内部错误
/// </summary>
InternalError = 1,
/// <summary>
/// from非法
/// </summary>
FromIllegal = 21,
/// <summary>
/// to非法
/// </summary>
ToIllegal = 22,
/// <summary>
/// coords非法
/// </summary>
CoordsIllegal = 24,
/// <summary>
/// coords个数非法,超过限制
/// </summary>
CoordsCountIllegal = 25
}
</div>
3、定义API结果返回实体映射类
/// <summary>
/// 返回结果状态值, 成功返回0,其他值请查看附录。
/// </summary>
[JsonProperty(PropertyName = "result")]
public BaiduGeocodingResult Result;
}
public class BaiduGeocodingResult
{
/// <summary>
/// 经纬度坐标
/// </summary>
[JsonProperty(PropertyName = "location")]
public BaiduGeocodingLoaction Location;
/// <summary>
/// 位置的附加信息,是否精确查找。1为精确查找,0为不精确。
/// </summary>
[JsonProperty(PropertyName = "precise")]
public int Precise;
/// <summary>
/// 可信度
/// </summary>
[JsonProperty(PropertyName = "confidence")]
public int Confidence;
/// <summary>
/// 地址类型
/// </summary>
[JsonProperty(PropertyName = "level")]
&