Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> python for android : geocode 顯示地圖

python for android : geocode 顯示地圖

編輯:關於Android編程

顯示地圖 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'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(ugeocode,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

 


 

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved