def getCustomPathJSON(self,requestAsJson): try: # enter the curr loc from json here if requestAsJson.get('startLocation'): latidude = requestAsJson['startLocation']['latitude'] longitude = requestAsJson['startLocation']['longitude'] toReturn = DB.getCustomPath(latidude, longitude ,requestAsJson['endPlace']) else: toReturn = DB.getCustomPath(40.249145, -111.649238,requestAsJson['endPlace']) except Exception, e: toReturn = Parser.error(str(e))
def getDirections(self, requestAsJson, api_key): try: #requestAsJson = json.loads(requestAsJson1) if requestAsJson.get('startLocation'): latidude = requestAsJson['startLocation']['latitude'] longitude = requestAsJson['startLocation']['longitude'] dbInfo = DB.getCustomPath(latidude, longitude ,requestAsJson['endPlace']) else: startPlace = str(requestAsJson['startPlace']) endPlace = str(requestAsJson['endPlace']) dbInfo = DB.getPath(startPlace,endPlace) #return json.dumps(dbInfo) startLat = str(dbInfo["startCoord"]["latitude"]) startLong = str(dbInfo["startCoord"]["longitude"]) endLat = str(dbInfo["endCoord"]["latitude"]) endLong = str(dbInfo["endCoord"]["longitude"]) google = urllib2.urlopen("https://maps.googleapis.com/maps/api/directions/json?origin="+startLat+","+startLong+"&destination="+endLat+","+endLong+"&mode=walking&key="+api_key).read() direction = Directions(json.loads(google),dbInfo) #print json.dumps(direction.__dict__) return json.dumps(direction.__dict__) except Exception, e: toReturn = Parser.error(str(e)) return json.dumps("ERROR: " + str(toReturn))