4

我正在制作一个使用 Google Maps API v3 的网络应用程序。我想在地图上显示一些地方,这些地方存储在 Google 地图上用户的 Google 帐户的“我的地方”部分中。

我知道 google Maps API 支持 KML,我可以从 Google Maps My Places 下载 KML。但我想以编程方式执行此操作。

例子:

用户访问我的网站,使用他/她的 Google 凭据登录,他们可以看到他们保存的地点列表。单击其中一个后,该地点将出现在我的网络应用程序上的地图上。

请建议我如何去做。

我通过 Google Maps API 在特定帐户的“我的地点”中找到了此访问位置,并以这种方式进行了尝试:

import urllib2, urllib, re, getpass

username = 'abhishekworld'
senha = getpass.getpass('password' + username + ':')

dic = {
        'accountType':      'GOOGLE',
        'Email':            (username + '@gmail.com'),
        'Passwd':           senha,
        'service':          'local',
        'source':           'themappers'
        }
url = 'https://www.google.com/accounts/ClientLogin?' + urllib.urlencode(dic)
print url
output = urllib2.urlopen(url).read()
authid = output.strip().split('\n')[-1].split('=')[-1]

request = urllib2.Request('http://maps.google.com/maps/feeds/maps/default/full?access_token='+authid)
request.add_header('Authorization', 'GoogleLogin auth=%s' % authid)
source = urllib2.urlopen(request).read()
open('feed.xml','w').write(source)
for link in re.findall('<link rel=.alternate. type=.text/html. href=((.)[^\1]*?)>', source):
    s = link[0]
    if 'msa=0' in s:
        msid = s.split(";")[-1]
        print "https://maps.google.com/maps/ms?authuser=0&vps=2&ie=UTF8&msa=0&output=kml&"+msid

虽然这工作正常,但在几次登录后,Google 会向您发送一封电子邮件,内容是“报告了可疑活动”,所以我需要一个干净的解决方案。请让我知道是否有任何干净的方法可以做到这一点。

4

0 回答 0