当前位置:   article > 正文

python for android : 地图路径规划_python 地图 边界约束

python 地图 边界约束

地图路径规划 geopath.py

  1. # -*- coding: utf-8 -*-
  2. import android
  3. import urllib
  4. import urllib2
  5. import json
  6. import sys
  7. print sys.getdefaultencoding()
  8. reload(sys)
  9. sys.setdefaultencoding('utf-8')
  10. droid = android.Android()
  11. city = droid.dialogGetInput(u"geocode",u"请输入起点 start:",u'guangzhou').result
  12. city = urllib2.quote(city)
  13. print u'起点:',city
  14. url = u'http://maps.google.com/maps/api/geocode/json?address=%s&sensor=true&language=zh-CN'
  15. handler = urllib2.urlopen(url % city)
  16. js = json.load(handler)
  17. handler.close()
  18. address = js['results'][0]['address_components']
  19. for ad in address:
  20. print ad['long_name']
  21. location = js['results'][0]['geometry']['location']
  22. startLat = location['lat']
  23. startLng = location['lng']
  24. print js
  25. city = droid.dialogGetInput(u"geocode",u"请输入终点 end:",u'zhuhai').result
  26. city = urllib2.quote(city)
  27. print u'终点:',city
  28. url = u'http://maps.google.com/maps/api/geocode/json?address=%s&sensor=true&language=zh-CN'
  29. handler = urllib2.urlopen(url % city)
  30. js = json.load(handler)
  31. handler.close()
  32. address = js['results'][0]['address_components']
  33. for ad in address:
  34. print ad['long_name']
  35. location = js['results'][0]['geometry']['location']
  36. endLat = location['lat']
  37. endLng = location['lng']
  38. print js
  39. # 路径规划:
  40. url = 'http://maps.google.com/maps?f=d&saddr=%s%%20%s&daddr=%s%%20%s&hl=zh' % (startLat,startLng,endLat,endLng)
  41. print url
  42. droid.startActivity('android.intent.action.VIEW',url)
在 android 4.1 pad 上测试通过.
参考 http://blog.csdn.net/xyz_lmn/article/details/5968056

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/木道寻08/article/detail/997659
推荐阅读
相关标签
  

闽ICP备14008679号