123456789101112131415161718192021222324252627282930313233343536 |
- import json
- import requests
- from flask import current_app
- metadata_url = "https://maps.googleapis.com/maps/api/streetview/metadata"
- mapcrunch_url = "http://www.mapcrunch.com/_r/"
- def generate_coord(key):
- """
- Takes in a Google API key.
- Returns (latitude, longitude) of usable coord (where google has data).
- Returns None if, after trying several random points, no usable coords could be found.
-
- This function calls the streetview metadata endpoint - there is no quota consumed
- """
- points_res = requests.get(mapcrunch_url).text
- points_js = json.loads(points_res.strip("while(1); "))
- for lat, lng in points_js["points"]:
- params = {
- "key": key
- "location": f"{lat},{lng}"
- }
- js = requests.get(metadata_url, params=params).json()
- if js["status"] != "ZERO_RESULTS":
- return (lat, lng)
- def score(target, guess):
- """
- Takes in two (latitude, longitude) pairs and produces an int score.
- Score is in the (inclusive) range [0, 5000]
- Higher scores are closer.
- """
- pass
|