dailylog 8-07-20

1 minute read

GOAL:

I want to visualize zip code data on a map.

PROBLEM:

I need a map?

SOLUTION:

Plotly! Just like THIS!!

PROBLEM:

We don’t have plotly and are afraid to install it becuase it broke everything last time

SOLUTION:

JUST HECKIN’ DO IT BECAUSE WE CAN ALWAYS WIPE AND RESTART AGAIN!!

PROBLEM:

Plotly + zip codes don’t play nice unless you have FIPS data (which we can get but that is another animal)

SOLUTION:

Look at the example data and see what they are passing into example plot!! Very cool!! Lookst like Lat & Long!

PROBLEM:

Where do we get this “geo data”?

SOLUTION:

GoogleMaps!! Simply add the zip code to the end of the query string and WIN!!

PROBLEM:

This code

from urllib.request import urlopen
import json
with urlopen("http://maps.googleapis.com/maps/api/geocode/json?address=91011") as response:
    geoj = json.load(response)

Gives us this error

{
  "error_message": "You must use an API key to authenticate each request to Google Maps Platform APIs. For additional information, please refer to http://g.co/dev/maps-no-account",
  "results": [],
  "status": "REQUEST_DENIED"
}

SOLUTION:

(In my head) Oh since needing an API key is probably just an issue of backend vs frontend, I WILL CIRCUMVENT THE PROBLEM AND JUST USE JAVASCRIPT TO CREATE A CSV!!

PROBLEM:

THIS

var response = await fetch(
  "https://maps.googleapis.com/maps/api/geocode/json?address=91011"
);
var body = await response.json();

STILL GIVES US THIS ERROR

{error_message: "You must use an API key to authenticate each reque…, please refer to http://g.co/dev/maps-no-account", results: Array(0), status: "REQUEST_DENIED"}

SOLUTION:

Get an API key!! (Yes, we have to put billing info but there is no way we will exceed 200 requests per second so the likilhood we will get charged is slim… but I should still add a restriction)

PROBLEM:

Even WITH the API key

var response = await fetch(
  "https://maps.googleapis.com/maps/api/geocode/json?address=91011&key=MY_COOL_KEY"
);
var body = await response.json();

We get THIS error

{error_message: "This API project is not authorized to use this API.", results: Array(0), status: "REQUEST_DENIED"}

SOLUTION:

Go back to Google and add Geocoding API to your project

… and finally, the above request works :)

RESOURCES:

MY OWN PAST WORK WHAAAT

Working with GeoPandas / Exported GeoJson

GoogleMaps Geocoding Docs

Destructing geojson

HUGE repo of geojson data

UPYDASH

UPY