显示地图 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