Map Basics
Let’s first get our map of Boston. We aren’t going to draw anything yet.
import pandas as pd
import numpy as np
import gmplot
def Create_Map():
gmap = gmplot.GoogleMapPlotter.from_geocode("Boston")
gmap.draw("Boston_Real_Estate.html")
Create_Map()
The line gmap = gmplot.GoogleMapPlotter.from_geocode(“Boston”) creates a map object with Boston as it’s center. The draw function creates the file; check it out in your folder and you should see a regular Boston map.
To draw a square, we are going to need 4 points. The way we feed these points is an array of x coordinates, and an array of y coordinates to match. To draw a square where we will draw our grid, this code will work.
latMax = 42.39615117
latMin = 42.23108386
lonMax = -70.92757284
lonMin = -71.18485204
def Create_Map():
gmap = gmplot.GoogleMapPlotter.from_geocode("Boston")
xPoints=[latMax,latMin,latMin,latMax]
yPoints=[lonMin,lonMin,lonMax,lonMax]
gmap.polygon(xPoints, yPoints, color="#ff0000")
gmap.draw("Boston_Real_Estate.html")
Create_Map()
Let’s pull in our map data.
MapData = pd.DataFrame.from_csv("MapData.csv", encoding="UTF-8")
Challenge
Plot each individual square of the grid for our boston data.