diff --git a/config.example.json b/config.example.json
index 193178da..59dab8ed 100644
--- a/config.example.json
+++ b/config.example.json
@@ -234,6 +234,7 @@
},
"gmapsKey": "",
"nominatim": "",
+ "nominatimSchema": "{DisplayName}",
"despawnTimeMinimumMinutes": 5,
"reloadSubscriptionChangesMinutes": 1,
"maxNotificationsPerMinute": 10,
diff --git a/src/Configuration/WhConfig.cs b/src/Configuration/WhConfig.cs
index dce82072..bba2c4c9 100644
--- a/src/Configuration/WhConfig.cs
+++ b/src/Configuration/WhConfig.cs
@@ -105,6 +105,12 @@ public class WhConfig
[JsonProperty("nominatim")]
public string NominatimEndpoint { get; set; }
+ ///
+ /// Gets or sets the OpenStreetMaps Nominatim location string schema
+ ///
+ [JsonProperty("nominatimSchema")]
+ public string NominatimSchema { get; set; }
+
///
/// Gets or sets the minimum despawn time in minutes a Pokemon must have in order to send the alarm
///
diff --git a/src/Geofence/Location.cs b/src/Geofence/Location.cs
index cb0bb9a3..0896919f 100644
--- a/src/Geofence/Location.cs
+++ b/src/Geofence/Location.cs
@@ -10,9 +10,98 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
+ using SmartFormat;
+
using WhMgr.Configuration;
using WhMgr.Diagnostics;
+ ///
+ /// NominatimReverseLookup class
+ ///
+ public partial class NominatimReverseLookup
+ {
+ [JsonProperty("place_id")]
+ public long PlaceId { get; set; }
+
+ [JsonProperty("licence")]
+ public string Licence { get; set; }
+
+ [JsonProperty("osm_type")]
+ public string OsmType { get; set; }
+
+ [JsonProperty("osm_id")]
+ public long OsmId { get; set; }
+
+ [JsonProperty("lat")]
+ public decimal Lat { get; set; }
+
+ [JsonProperty("lon")]
+ public decimal Lon { get; set; }
+
+ [JsonProperty("place_rank")]
+ public long PlaceRank { get; set; }
+
+ [JsonProperty("category")]
+ public string Category { get; set; }
+
+ [JsonProperty("type")]
+ public string Type { get; set; }
+
+ [JsonProperty("importance")]
+ public long Importance { get; set; }
+
+ [JsonProperty("addresstype")]
+ public string Addresstype { get; set; }
+
+ [JsonProperty("name")]
+ public string Name { get; set; }
+
+ [JsonProperty("display_name")]
+ public string DisplayName { get; set; }
+
+ [JsonProperty("address")]
+ public NominatimAddress Address { get; set; }
+
+ [JsonProperty("boundingbox")]
+ public decimal[] Boundingbox { get; set; }
+ }
+
+ ///
+ /// NominatimAddress class
+ ///
+ public partial class NominatimAddress
+ {
+ [JsonProperty("house_number")]
+ public string HouseNumber { get; set; }
+
+ [JsonProperty("road")]
+ public string Road { get; set; }
+
+ [JsonProperty("neighbourhood")]
+ public string Neighbourhood { get; set; }
+
+ [JsonProperty("suburb")]
+ public string Suburb { get; set; }
+
+ [JsonProperty("town")]
+ private string Town { set { City = value; } }
+
+ [JsonProperty("city")]
+ public string City { get; set; }
+
+ [JsonProperty("state")]
+ public string State { get; set; }
+
+ [JsonProperty("postcode")]
+ public string Postcode { get; set; }
+
+ [JsonProperty("country")]
+ public string Country { get; set; }
+
+ [JsonProperty("country_code")]
+ public string CountryCode { get; set; }
+ }
+
///
/// Geocoordinate location
///
@@ -77,7 +166,7 @@ public Location GetAddress(WhConfig config)
return GetGoogleAddress(City, Latitude, Longitude, config.GoogleMapsKey);
if (!string.IsNullOrEmpty(config.NominatimEndpoint))
- return GetNominatimAddress(City, Latitude, Longitude, config.NominatimEndpoint);
+ return GetNominatimAddress(City, Latitude, Longitude, config.NominatimEndpoint, config.NominatimSchema);
return null;
}
@@ -141,8 +230,9 @@ private Location GetGoogleAddress(string city, double lat, double lng, string gm
/// Latitude to lookup
/// Longitude to lookup
/// Nominatim endpoint
+ /// Nominatim schema
///
- private Location GetNominatimAddress(string city, double lat, double lng, string endpoint)
+ private Location GetNominatimAddress(string city, double lat, double lng, string endpoint, string nominatimSchema)
{
var unknown = "Unknown";
var url = $"{endpoint}/reverse?format=jsonv2&lat={lat}&lon={lng}";
@@ -153,8 +243,9 @@ private Location GetNominatimAddress(string city, double lat, double lng, string
wc.Proxy = null;
wc.Headers.Add("User-Agent", Strings.BotName);
var json = wc.DownloadString(url);
- dynamic obj = JsonConvert.DeserializeObject(json);
- return new Location(Convert.ToString(obj.display_name), city ?? unknown, Convert.ToDouble(obj.lat), Convert.ToDouble(obj.lon));
+ dynamic obj = JsonConvert.DeserializeObject(json);
+ var location_string = Smart.Format(nominatimSchema, obj);
+ return new Location(location_string, city ?? unknown, Convert.ToDouble(obj.Lat), Convert.ToDouble(obj.Lon));
}
}
catch (Exception ex)
diff --git a/src/WhMgr.csproj b/src/WhMgr.csproj
index 0fb2a064..4f3ce957 100644
--- a/src/WhMgr.csproj
+++ b/src/WhMgr.csproj
@@ -49,6 +49,7 @@
+