python for android : 地图路径规划

地图路径规划 geopath.py

# -*- coding: utf-8 -*-
import android
import urllib
import urllib2
import json
import sys
print  sys.getdefaultencoding()
reload(sys)
sys.setdefaultencoding('utf-8')

droid = android.Android()
city = droid.dialogGetInput(u"geocode",u"请输入起点 start:",u'guangzhou').result
city = urllib2.quote(city)
print u'起点:',city

url = u'http://maps.google.com/maps/api/geocode/json?address=%s&sensor=true&language=zh-CN'
handler = urllib2.urlopen(url % city)
js = json.load(handler)
handler.close()

address = js['results'][0]['address_components']
for ad in address:
    print ad['long_name']

location = js['results'][0]['geometry']['location']
startLat = location['lat']
startLng = location['lng']
print js

city = droid.dialogGetInput(u"geocode",u"请输入终点 end:",u'zhuhai').result
city = urllib2.quote(city)
print u'终点:',city

url = u'http://maps.google.com/maps/api/geocode/json?address=%s&sensor=true&language=zh-CN'
handler = urllib2.urlopen(url % city)
js = json.load(handler)
handler.close()

address = js['results'][0]['address_components']
for ad in address:
    print ad['long_name']

location = js['results'][0]['geometry']['location']
endLat = location['lat']
endLng = location['lng']
print js

# 路径规划:
url = 'http://maps.google.com/maps?f=d&saddr=%s%%20%s&daddr=%s%%20%s&hl=zh' % (startLat,startLng,endLat,endLng)
print url
droid.startActivity('android.intent.action.VIEW',url)
在 android 4.1 pad 上测试通过.
参考 http://blog.csdn.net/xyz_lmn/article/details/5968056

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值