GPSConverter.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using Azylee.Core.DataUtils.CollectionUtils;
  2. using Azylee.YeahWeb.HttpUtils;
  3. using Newtonsoft.Json;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. namespace Azylee.YeahWeb.BaiDuWebAPI.GPSAPI
  9. {
  10. public class GPSConverter
  11. {
  12. /// <summary>
  13. /// 设备GPS定位转换为BaiduGPS信息
  14. /// </summary>
  15. /// <param name="ak"></param>
  16. /// <param name="longitude">经度(东经西经,纵向)</param>
  17. /// <param name="latitude">纬度(北纬南纬,横向)</param>
  18. /// <param name="x"></param>
  19. /// <param name="y"></param>
  20. /// <returns></returns>
  21. public static bool DeviceGPSToBaiduGPS(string ak, double longitude, double latitude, out double x, out double y)
  22. {
  23. x = 0;
  24. y = 0;
  25. try
  26. {
  27. string url = $"http://api.map.baidu.com/geoconv/v1/?coords={longitude},{latitude}&from=1&to=5&ak={ak}";
  28. string rs = HttpTool.Get(url);
  29. GPSPointWebModel rsobj = JsonConvert.DeserializeObject<GPSPointWebModel>(rs);
  30. if (rsobj != null && ListTool.HasElements(rsobj.result))
  31. {
  32. x = rsobj.result[0].x;
  33. y = rsobj.result[0].y;
  34. return true;
  35. }
  36. }
  37. catch { }
  38. return false;
  39. }
  40. }
  41. }