[gnome-maps/wip/mlundblad/photon-geocode: 2/4] WIP: add Photon geocode module
- From: Marcus Lundblad <mlundblad src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps/wip/mlundblad/photon-geocode: 2/4] WIP: add Photon geocode module
- Date: Wed, 24 Apr 2019 21:16:15 +0000 (UTC)
commit 12737964a3f5b50e8954d02923c26e37b71a0171
Author: Marcus Lundblad <ml update uu se>
Date: Tue Apr 23 23:12:41 2019 +0200
WIP: add Photon geocode module
src/org.gnome.Maps.src.gresource.xml | 1 +
src/photonGeocode.js | 63 ++++++++++++++++++++++++++++++++++++
2 files changed, 64 insertions(+)
---
diff --git a/src/org.gnome.Maps.src.gresource.xml b/src/org.gnome.Maps.src.gresource.xml
index 4abd878..df2b814 100644
--- a/src/org.gnome.Maps.src.gresource.xml
+++ b/src/org.gnome.Maps.src.gresource.xml
@@ -48,6 +48,7 @@
<file>osmTypes.js</file>
<file>osmUtils.js</file>
<file>overpass.js</file>
+ <file>photonGeocode.js</file>
<file>place.js</file>
<file>placeBubble.js</file>
<file>placeEntry.js</file>
diff --git a/src/photonGeocode.js b/src/photonGeocode.js
new file mode 100644
index 0000000..2fa6c10
--- /dev/null
+++ b/src/photonGeocode.js
@@ -0,0 +1,63 @@
+/* -*- Mode: JS2; indent-tabs-mode: nil; js2-basic-offset: 4 -*- */
+/* vim: set et ts=4 sw=4: */
+/*
+ * Copyright (c) 2019 Marcus Lundblad.
+ *
+ * GNOME Maps is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * GNOME Maps is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with GNOME Maps; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Marcus Lundblad <ml update uu se>
+ */
+
+const Format = imports.format;
+
+const GLib = imports.gi.GLib;
+const Soup = imports.gi.Soup;
+
+const Utils = imports.utils;
+
+const _BASE_URL = 'https://photon.komoot.de/api/';
+
+var PhotonGeocode = class {
+ constructor() {
+ this._session = new Soup.Session({ user_agent : 'gnome-maps/' + pkg.version });
+ }
+
+ search(string, latitude, longitude) {
+ Utils.debug('photon search: ' + string);
+ let url = this._buildURL(string, latitude, longitude);
+ let msg = Soup.Message.new('GET', url);
+ Utils.debug('URL: ' + url);
+ this._session.queue_message(msg, (session, message) => {
+ try {
+ Utils.debug('message: ' + message.response_body.data);
+ /*
+ let result = this._parseMessage(message);
+ if (!result)
+ callback(null, null);
+ else
+ callback(result, null);
+ */
+ } catch (e) {
+ callback(null, e);
+ }
+ });
+ }
+
+ _buildURL(string, latitude, longitude) {
+ return Format.vprintf('%s?q=%s&lat=%s&lon=%s',
+ [ _BASE_URL,
+ GLib.uri_escape_string(string, null, false),
+ latitude, longitude]);
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]