Added openstreetmaps nominatim service as default geolocation provider.

That's now possible, because we can easily switch the provider from inside the extension.
This is recommended by them.
merge-requests/218/head
Jens Lody 9 years ago
parent 6dea6cf25c
commit 37a154c86f
  1. 7
      data/org.gnome.shell.extensions.openweather.gschema.xml.in
  2. 1
      data/weather-settings.ui
  3. 50
      src/prefs.js

@ -4,8 +4,9 @@
<value nick="forecast.io" value="1" /> <value nick="forecast.io" value="1" />
</enum> </enum>
<enum id="org.gnome.shell.extensions.openweather.geolocation-provider"> <enum id="org.gnome.shell.extensions.openweather.geolocation-provider">
<value nick="geocode" value="0" /> <value nick="openstreetmaps" value="0" />
<value nick="mapquest" value="1" /> <value nick="geocode" value="1" />
<value nick="mapquest" value="2" />
</enum> </enum>
<enum id="org.gnome.shell.extensions.openweather.unit"> <enum id="org.gnome.shell.extensions.openweather.unit">
<value nick="celsius" value="0" /> <value nick="celsius" value="0" />
@ -52,7 +53,7 @@
<_summary>Weather Provider</_summary> <_summary>Weather Provider</_summary>
</key> </key>
<key name="geolocation-provider" enum="org.gnome.shell.extensions.openweather.geolocation-provider"> <key name="geolocation-provider" enum="org.gnome.shell.extensions.openweather.geolocation-provider">
<default>'geocode'</default> <default>'openstreetmaps'</default>
<_summary>Geolocation Provider</_summary> <_summary>Geolocation Provider</_summary>
</key> </key>
<key name="unit" enum="org.gnome.shell.extensions.openweather.unit"> <key name="unit" enum="org.gnome.shell.extensions.openweather.unit">

@ -571,6 +571,7 @@
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<items> <items>
<item>https://nominatim.openstreetmap.org/</item>
<item>https://geocode.farm/</item> <item>https://geocode.farm/</item>
<item>https://open.mapquestapi.com/nominatim/</item> <item>https://open.mapquestapi.com/nominatim/</item>
</items> </items>

@ -73,6 +73,8 @@ const OPENWEATHER_URL_MAPQUEST_BASE = 'https://open.mapquestapi.com/nominatim/v1
const OPENWEATHER_URL_MAPQUEST_FIND = OPENWEATHER_URL_MAPQUEST_BASE + 'search.php'; const OPENWEATHER_URL_MAPQUEST_FIND = OPENWEATHER_URL_MAPQUEST_BASE + 'search.php';
const OPENWEATHER_URL_GEOCODE_BASE = 'https://www.geocode.farm/v3/'; const OPENWEATHER_URL_GEOCODE_BASE = 'https://www.geocode.farm/v3/';
const OPENWEATHER_URL_GEOCODE_FIND = OPENWEATHER_URL_GEOCODE_BASE + 'json/forward'; const OPENWEATHER_URL_GEOCODE_FIND = OPENWEATHER_URL_GEOCODE_BASE + 'json/forward';
const OPENWEATHER_URL_OSM_BASE = 'https://nominatim.openstreetmap.org/';
const OPENWEATHER_URL_OSM_FIND = OPENWEATHER_URL_OSM_BASE + 'search';
// Keep enums in sync with GSettings schemas // Keep enums in sync with GSettings schemas
const WeatherProvider = { const WeatherProvider = {
@ -82,8 +84,9 @@ const WeatherProvider = {
}; };
const GeolocationProvider = { const GeolocationProvider = {
GEOCODE: 0, OPENSTREETMAP: 0,
MAPQUEST: 1 GEOCODE: 1,
MAPQUEST: 2
}; };
let _httpSession; let _httpSession;
@ -187,7 +190,48 @@ const WeatherPrefsWidget = new GObject.Class({
this.searchMenu.show_all(); this.searchMenu.show_all();
this.searchMenu.popup(null, null, Lang.bind(this, this.placeSearchMenu), 0, this.searchName); this.searchMenu.popup(null, null, Lang.bind(this, this.placeSearchMenu), 0, this.searchName);
if (this.geolocation_provider == GeolocationProvider.MAPQUEST) { if (this.geolocation_provider == GeolocationProvider.OPENSTREETMAPS) {
let params = {
format: 'json',
addressdetails: '1',
q: location
};
this.loadJsonAsync(OPENWEATHER_URL_OSM_FIND, params, Lang.bind(this, function() {
this.clearSearchMenu();
if (!arguments[0]) {
let item = new Gtk.MenuItem({
label: _("Invalid data when searching for \"%s\"").format(location)
});
this.searchMenu.append(item);
} else {
let newCity = arguments[0];
if (Number(newCity.length) < 1) {
let item = new Gtk.MenuItem({
label: _("\"%s\" not found").format(location)
});
this.searchMenu.append(item);
} else {
var m = {};
for (var i in newCity) {
let cityText = newCity[i].display_name;
let cityCoord = "[" + newCity[i].lat + "," + newCity[i].lon + "]";
let item = new Gtk.MenuItem({
label: cityText + " " + cityCoord
});
item.connect("activate", Lang.bind(this, this.onActivateItem));
this.searchMenu.append(item);
}
}
}
this.searchMenu.show_all();
this.searchMenu.popup(null, null, Lang.bind(this, this.placeSearchMenu), 0, this.searchName);
return 0;
}));
} else if (this.geolocation_provider == GeolocationProvider.MAPQUEST) {
if (this.geolocation_appid_mapquest === '') { if (this.geolocation_appid_mapquest === '') {
this.clearSearchMenu(); this.clearSearchMenu();
let item = new Gtk.MenuItem({ let item = new Gtk.MenuItem({

Loading…
Cancel
Save