/// <summary> /// Gets the geolocation of record /// </summary> /// <param name="resultRow">Result row</param> /// <returns>Location for given result row</returns> public static Location Location(UPMResultRow resultRow) { UPMGpsXField gpsXField = null; UPMGpsYField gpsYField = null; foreach (UPMField field in resultRow.Fields) { if (field is UPMGpsXField) { gpsXField = (UPMGpsXField)field; } else if (field is UPMGpsYField) { gpsYField = (UPMGpsYField)field; } } return(new Location(gpsXField?.StringValue?.ToDouble() ?? 0, gpsYField?.StringValue?.ToDouble() ?? 0)); }
private void AddDistanceFieldToRow(UPMResultRow resultRow) { UPMGpsXField gpsXField = null; UPMGpsYField gpsYField = null; foreach (UPMField field in resultRow.Fields) { if (field is UPMGpsXField) { gpsXField = (UPMGpsXField)field; } else if (field is UPMGpsYField) { gpsYField = (UPMGpsYField)field; } } var target = new Location(gpsXField.StringValue.ToDouble(), gpsYField.StringValue.ToDouble()); var locA = new Location(target.Longitude, target.Latitude); var locB = new Location(this.currentUserLocation.Longitude, this.currentUserLocation.Latitude); var distance = locA.DistanceFromLocation(locB); this.resultRowsToSort.Add(new GeoUPMResultRow(resultRow, distance)); uint fieldCount = 0; foreach (UPMField field in resultRow.Fields) { if (field.Hidden == false) { fieldCount++; } } var rowIdentifier = (RecordIdentifier)resultRow.Identifier; UPMStringField distanceField = new UPMStringField(rowIdentifier.IdentifierWithFieldId("Distance")); // TODO: Localization not working and will be handled in CRM-5629 // distanceField.FieldValue = $"{(distance / 1000).ToString("0.##")} {LocalizationKeys.upTextDistanceFilterKmValue}"; distanceField.FieldValue = $"{(distance / 1000).ToString("0.##")} km"; resultRow.Fields.Add(distanceField); }