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(ugeocode,u請輸入 city:,u'guangzhou').result
city = urllib2.quote(city)
print city

url = u'https://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(ugeocode,u請輸入 city:,u'guangzhou').result
city = urllib2.quote(city)
print city

url = u'https://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

 

 

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *