Skip to content

Instantly share code, notes, and snippets.

@eirenik0
Last active December 18, 2015 19:09
Show Gist options
  • Save eirenik0/5830546 to your computer and use it in GitHub Desktop.
Save eirenik0/5830546 to your computer and use it in GitHub Desktop.
implement the function gmaps_img(points) that returns the google maps image
from collections import namedtuple
# make a basic Point class
Point = namedtuple('Point', ["lat", "lon"])
points = [Point(1,2),
Point(3,4),
Point(5,6)]
# implement the function gmaps_img(points) that returns the google maps image
# for a map with the points passed in. A example valid response looks like
# this:
#
# http://maps.googleapis.com/maps/api/staticmap?size=380x263&sensor=false&markers=1,2&markers=3,4
#
# Note that you should be able to get the first and second part of an individual Point p with
# p.lat and p.lon, respectively, based on the above code. For example, points[0].lat would
# return 1, while points[2].lon would return 6.
GMAPS_URL = "http://maps.googleapis.com/maps/api/staticmap?size=380x263&sensor=false&"
def gmaps_img(points):
markers = "&".join("markers=%s,%s" % (point.lat, point.lon) for point in points)
return GMAPS_URL + markers
###Your code here
print gmaps_img(points)
@eirenik0
Copy link
Author

If I define the namedtuple as 'Point', then pickle is happy:

Point = namedtuple('Point','x y')
pp = Point(1,2)
ppp = pickle.dumps(pp)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment