LocationInfo.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import json
  4. from alipay.aop.api.constant.ParamConstants import *
  5. class LocationInfo(object):
  6. def __init__(self):
  7. self._latitude = None
  8. self._longitude = None
  9. self._region_code = None
  10. @property
  11. def latitude(self):
  12. return self._latitude
  13. @latitude.setter
  14. def latitude(self, value):
  15. self._latitude = value
  16. @property
  17. def longitude(self):
  18. return self._longitude
  19. @longitude.setter
  20. def longitude(self, value):
  21. self._longitude = value
  22. @property
  23. def region_code(self):
  24. return self._region_code
  25. @region_code.setter
  26. def region_code(self, value):
  27. self._region_code = value
  28. def to_alipay_dict(self):
  29. params = dict()
  30. if self.latitude:
  31. if hasattr(self.latitude, 'to_alipay_dict'):
  32. params['latitude'] = self.latitude.to_alipay_dict()
  33. else:
  34. params['latitude'] = self.latitude
  35. if self.longitude:
  36. if hasattr(self.longitude, 'to_alipay_dict'):
  37. params['longitude'] = self.longitude.to_alipay_dict()
  38. else:
  39. params['longitude'] = self.longitude
  40. if self.region_code:
  41. if hasattr(self.region_code, 'to_alipay_dict'):
  42. params['region_code'] = self.region_code.to_alipay_dict()
  43. else:
  44. params['region_code'] = self.region_code
  45. return params
  46. @staticmethod
  47. def from_alipay_dict(d):
  48. if not d:
  49. return None
  50. o = LocationInfo()
  51. if 'latitude' in d:
  52. o.latitude = d['latitude']
  53. if 'longitude' in d:
  54. o.longitude = d['longitude']
  55. if 'region_code' in d:
  56. o.region_code = d['region_code']
  57. return o