python for android : geocode 显示地图

显示地图 geocode.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"请输入 city:",u'guangzhou').result
city = urllib2.quote(city)
print 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']
uri = u'geo:%s,%s' % (location['lat'], location['lng'])
print uri
# 显示地图:
droid.startActivity('android.intent.action.VIEW',uri)

本人android 4.1 pad 没有 gps , 如何显示地图?
从geo.py 开始研究:

# -*- coding: utf-8 -*-
import android
import urllib
import urllib2
import json

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

url = u'http://maps.google.com/maps/api/geocode/json?address=%s&sensor=true&language=zh-CN'
handler = urllib2.urlopen(url % city)
data = handler.read()
handler.close()
print data
参考 http://blog.csdn.net/xyz_lmn/article/details/5968056


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值