@@ -182,6 +182,37 @@ public static void SetUserDescription(this Event ev, UserDescription description
182
182
ev . Data [ Event . KnownDataKeys . UserDescription ] = description ;
183
183
}
184
184
185
+ /// <summary>
186
+ /// Sets the event geo coordinates. Can be either "lat,lon" or an IP address that will be used to auto detect the geo coordinates.
187
+ /// </summary>
188
+ /// <param name="coordinates">The event coordinates.</param>
189
+ public static void SetGeo ( this Event ev , string coordinates ) {
190
+ if ( String . IsNullOrWhiteSpace ( coordinates ) ) {
191
+ ev . Geo = null ;
192
+ return ;
193
+ }
194
+
195
+ if ( coordinates . Contains ( "," ) || coordinates . Contains ( "." ) || coordinates . Contains ( ":" ) )
196
+ ev . Geo = coordinates ;
197
+ else
198
+ throw new ArgumentException ( "Must be either lat,lon or an IP address." , "coordinates" ) ;
199
+ }
200
+
201
+
202
+ /// <summary>
203
+ /// Sets the event geo coordinates.
204
+ /// </summary>
205
+ /// <param name="latitude">The event latitude.</param>
206
+ /// <param name="longitude">The event longitude.</param>
207
+ public static void SetGeo ( this Event ev , double latitude , double longitude ) {
208
+ if ( latitude < - 90.0 || latitude > 90.0 )
209
+ throw new ArgumentOutOfRangeException ( "latitude" , "Must be a valid latitude value between -90.0 and 90.0." ) ;
210
+ if ( longitude < - 180.0 || longitude > 180.0 )
211
+ throw new ArgumentOutOfRangeException ( "longitude" , "Must be a valid longitude value between -180.0 and 180.0." ) ;
212
+
213
+ ev . Geo = latitude . ToString ( "#0.0#######" ) + "," + longitude . ToString ( "#0.0#######" ) ;
214
+ }
215
+
185
216
/// <summary>
186
217
/// Sets the manual stacking key
187
218
/// </summary>
0 commit comments