[gnome-maps/wip/mlundblad/mapbox-geocode: 1/3] WIP: add Mapbox geocode module
- From: Marcus Lundblad <mlundblad src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps/wip/mlundblad/mapbox-geocode: 1/3] WIP: add Mapbox geocode module
- Date: Wed, 24 Apr 2019 17:32:18 +0000 (UTC)
commit 1c79df539827f69e89ec01025712f40440c6b6df
Author: Marcus Lundblad <ml update uu se>
Date: Tue Apr 23 23:12:41 2019 +0200
WIP: add Mapbox geocode module
fixup! WIP: add Mapbox geocode module
src/mapboxGeocode.js | 65 ++++++++++++++++++++++++++++++++++++
src/org.gnome.Maps.src.gresource.xml | 1 +
2 files changed, 66 insertions(+)
---
diff --git a/src/mapboxGeocode.js b/src/mapboxGeocode.js
new file mode 100644
index 0000000..e5f154b
--- /dev/null
+++ b/src/mapboxGeocode.js
@@ -0,0 +1,65 @@
+/* -*- 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://api.mapbox.com/geocoding/v5/mapbox.places';
+const _API_KEY =
'pk.eyJ1IjoiZ25vbWUtbWFwcyIsImEiOiJjaXF3a3lwbXkwMDJwaTBubmZlaGk4cDZ6In0.8aukTfgjzeqATA8eNItPJA&';
+
+var MapboxGeocode = class {
+ constructor() {
+ this._session = new Soup.Session({ user_agent : 'gnome-maps/' + pkg.version });
+ }
+
+ search(string, latitude, longitude) {
+ Utils.debug('mapbox 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/%s.json?access_token=%s?proximity=%s,%s',
+ [ _BASE_URL,
+ GLib.uri_escape_string(string, null, false),
+ _API_KEY,
+ longitude, latitude]);
+ }
+}
diff --git a/src/org.gnome.Maps.src.gresource.xml b/src/org.gnome.Maps.src.gresource.xml
index 4abd878..f2dff50 100644
--- a/src/org.gnome.Maps.src.gresource.xml
+++ b/src/org.gnome.Maps.src.gresource.xml
@@ -32,6 +32,7 @@
<file>longPrintLayout.js</file>
<file>main.js</file>
<file>mainWindow.js</file>
+ <file>mapboxGeocode.js</file>
<file>mapBubble.js</file>
<file>mapMarker.js</file>
<file>mapSource.js</file>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]