From c797b450df25b33ed4b8571d1c53eceee161368a Mon Sep 17 00:00:00 2001 From: Daniel Grams Date: Sun, 28 Jun 2020 15:32:22 +0200 Subject: [PATCH] GeoCoordinates --- jsonld.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/jsonld.py b/jsonld.py index 3d14162..d2115d2 100644 --- a/jsonld.py +++ b/jsonld.py @@ -1,4 +1,5 @@ import datetime +import decimal from json import JSONEncoder from flask import url_for @@ -8,6 +9,8 @@ class DateTimeEncoder(JSONEncoder): def default(self, obj): if isinstance(obj, (datetime.date, datetime.datetime)): return obj.isoformat() + if isinstance(obj, decimal.Decimal): + return float(obj) def get_sd_for_org(organization): result = {} @@ -49,6 +52,13 @@ def get_sd_for_location(location): return result +def get_sd_for_geo(location): + result = {} + result["@type"] = "GeoCoordinates" + result["latitude"] = location.latitude + result["longitude"] = location.longitude + return result + def get_sd_for_place(place): result = {} result["@type"] = "Place" @@ -59,6 +69,9 @@ def get_sd_for_place(place): if place.location: result["address"] = get_sd_for_location(place.location) + if place.location.latitude != 0: + result["geo"] = get_sd_for_geo(place.location) + if place.photo_id: result["photo"] = url_for('image', id=place.photo_id)