How to get list of my places from Google Maps programmatically?

谁说我不能喝 提交于 2019-12-12 07:38:20

问题


I am making a web app which is using Google Maps API v3. I want to display some places on the map which are stored on the user's Google account's "My Places" section on Google Maps.

I know that google Maps API support KML and I can download KML from Google Maps My Places. But I want to do this programmatically.

Example:

A user comes to my website, log in using his/her Google credentials and they can see the list of their saved places. After clicking on one of them, that place will appear on the map which is on my web app.

Please suggest how I go about it.

I found this Access locations in My Places of a particular account through Google Maps API and tried it this way:

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

Although this works fine, after a few logins, Google sends you an email saying "suspicious activity reported", so I need a clean solution. Please let me know if there is any clean way to do this.

来源:https://stackoverflow.com/questions/17746189/how-to-get-list-of-my-places-from-google-maps-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!