net 腾讯地图 百度地图逆地址解析

来源:互联网 发布:手机怎么激活淘宝店铺 编辑:程序博客网 时间:2024/06/06 00:43

#region 方法 GetQQMaoAddress(string strlatitude, string strlongitude) 通过经纬度获取QQmap地址
    /// <summary>
    /// 
    /// </summary>
    /// <param name="strlatitude"></param>
    /// <param name="strlongitude"></param>
    /// <returns></returns>
    public string GetQQMaoAddress(string strlatitude, string strlongitude)
    {
        string strResult = "", strOpenId = "";
        try
        {
            if (strlatitude != "" && strlongitude != "")
            {
                TWeiXinQyHelper weihelper = new TWeiXinQyHelper();
                string strJson = weihelper.GetData("http://apis.map.qq.com/ws/geocoder/v1/?location=" + strlatitude + "," + strlongitude + "&key=密钥");
                string strCode = @"\""address\"":\s*""(?'address'[^""]*)""";
                Regex regex = new Regex(strCode, RegexOptions.IgnoreCase);
                if (regex.IsMatch(strJson))
                {
                    MatchCollection matches = regex.Matches(strJson);
                    StringBuilder stringBuilder = new StringBuilder();
                    foreach (Match match in matches)
                    {
                        strOpenId = match.Groups["address"].Value;
                    }
                }


                strResult = strOpenId;
            }
        }
        catch
        {
            strResult = string.Empty;
        }
        return strResult;
    }
    #endregion


#region 方法 GetBaiduMaoAddress(string strlatitude, string strlongitude) 通过经纬度获取QQmap地址

    /// <summary>
    /// </summary>
    /// <param name="strlatitude"></param>
    /// <param name="strlongitude"></param>
    /// <returns></returns>
    public string GetBaiduMaoAddress(string strlatitude, string strlongitude)
    {
        string strResult = "", strOpenId = "";
        try
        {
            if (strlatitude != "" && strlongitude != "")
            {
                TWeiXinQyHelper weihelper = new TWeiXinQyHelper();
                string strJson = weihelper.GetData("http://api.map.baidu.com/geocoder/v2/?coordtype=wgs84ll&location=" + strlatitude + "," + strlongitude + "&output=json&poi=0&ak=密钥");
                string strCode = @"\""sematic_description\"":\s*""(?'sematic_description'[^""]*)""";
                Regex regex = new Regex(strCode, RegexOptions.IgnoreCase);
                if (regex.IsMatch(strJson))
                {
                    MatchCollection matches = regex.Matches(strJson);
                    StringBuilder stringBuilder = new StringBuilder();
                    foreach (Match match in matches)
                    {
                        strOpenId = match.Groups["sematic_description"].Value;
                    }
                }


                strResult = strOpenId;
            }
        }
        catch
        {
            strResult = string.Empty;
        }
        return strResult;
    }
    #endregion
原创粉丝点击