LBS上传到百度地图

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LBS上传到百度地图相关的知识,希望对你有一定的参考价值。

准备:

第一步:注册百度地图开发者账号

第二步:使用开发者账号注册相对应秘钥

在LBS后台添加所需要上传的字段

1,添加WebClientHelper帮助类

2,LBS帮助类

  private string ak = "WsjYicnWeleiuu8bmAYLy08m";//用户的访问权限key      

   private string petLocationId = "80305";//(位置数据表的标示)    

  private string petHospitalId = "90736";//(位置数据表的标示)

 WebClientHelper clientHelper = new WebClientHelper();       

  /// <summary> /// 生成文件上传到LBS(丢失、拾获、领养)/// </summary>        

/// <param name="title">公告标题</param>        

/// <param name="lng">经度</param>       

  /// <param name="lat">纬度</param>       

  /// <param name="address">地址(标准的地址信息,如北京市XX区XX街(路)XX号,或名胜古迹、标志性建筑物,或“XX路与XX路交叉口”描述方式)</param>         /// <param name="petpicture">图片(互联网图片)</param>        

 /// <param name="sex">性别</param>      

 /// <param name="noticedate">日期(或发布日期):2014-03-20</param>        

/// <param name="state">状态标记:1,2,3,4</param>        

/// <param name="filePath">上传文件的存放路径:写成Server.MapPath("/tempfile/"),存放到服务器</param>        

/// <param name="customPoiId">自定义id(便于更新LBS里的数据信息)</param>        

/// <returns></returns>        

public bool UploadLoacationToLBS(string title, string lng, string lat, string address, string sex, string noticedate, int state, string filePath, string customPoiId)       

  {          

   if (string.IsNullOrEmpty(lng) || string.IsNullOrEmpty(lat))     

        {          

       LogHelper.WriteLog("地址解析失败:经纬度为空");        

         return false;        

     }          

   string fileName = string.Format("{0:yyyy-MM-dd}", DateTime.Now).Replace("-", "") + RandomCodeHelper.GetNumberRandomCode(4) + ".csv";             string fullPath = filePath + fileName;     //重置csv文件名称

        if (File.Exists(fullPath))        //判断该csv文件名称是否重复

     {            

     File.Delete(fullPath);    //删除重复文件   

      }             try             {       

       //将内容写入csv文件,存入服务器

          FileStream fs = new FileStream(fullPath, FileMode.Create, FileAccess.Write);    

             StreamWriter sw = new StreamWriter(fs, Encoding.Default);      

           string fieldTilte = "title,address,longitude,latitude,coord_type,,CustomPoiId,state,noticedate,sex,variety,feature,petpicture";   

              sw.WriteLine(fieldTilte);             

    //sw.WriteLine(title + "," + address + "," + lng + "," + lat + ",1,," + petpicture + "," + sex + "," + noticedate + "," + state);             

    sw.WriteLine(title + "," + address + "," + lng + "," + lat + ",1,," + customPoiId + "," + state + "," + noticedate + "," + sex +  "," + petpicture);          

       sw.Close();              

      fs.Close();          

       return UploadLoacationToLBS(fullPath, petLocationId); //文件内容写入完成,上传到LBS方法      

      }             catch (Exception ex)             {       

          LogHelper.WriteLog("上传文件到LBS出错:", ex);         

        return false;         

    }

        }

----------------------------------------------------------------------LBS上传坐标------------------------------------------------------------------------------------------

  /// <summary>
        /// 上传数据文件
        /// </summary>
        /// <param name="fullPath">文件路径</param>
        /// <param name="geotableId">位置数据表的标示(id)</param>
        /// <returns></returns>
        public bool UploadLoacationToLBS(string fullPath, string geotableId)
        {
            string result = clientHelper.UploadFile("http://api.map.baidu.com/geodata/v3/poi/upload", "ak=" + ak + "&geotable_id=" + geotableId + "", "poi_list=" + fullPath);
            LogHelper.WriteLog("上传到LBS返回值记录:" + result);
            if (result.Contains("\"status\": 0,"))
            {
                //File.Delete(fullPath);
                return true;
            }
            else
            {
                return false;
            }
        }

 

注:上传会有延迟,目前用后台异步解决,各位大神多多指教

 

以上是关于LBS上传到百度地图的主要内容,如果未能解决你的问题,请参考以下文章

百度LBS地图的Web端开发实战

Android LBS 百度地图

Android LBS 百度地图(参考: 《第一行代码》第二版(郭霖著)11.3.4 显示看得懂的定位信息:准确文字地址)

与百度LBS开放平台相比,高德地图API有啥优势?

LBS高德地图百度地图的经纬度科普|MySQL和编程语言是如何计算两个坐标之间的距离?

LBS高德地图百度地图的经纬度科普|MySQL和编程语言是如何计算两个坐标之间的距离?