GPSConverter.cs 1.3 KB

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