ArnoldV/Our.Umbraco.GMaps

Address doesn't have a constructor that takes 0 arguments

Closed this issue · 0 comments

Previous we could do something like the following the populate data to Our.Umbraco.GMaps.Models.Map object and serialize the JSON to store in a property.

However in v2 it seems the Our.Umbraco.GMaps.Models.Address doesn't have a constructor that takes 0 arguments.

if (googleAddress != null)
{
    var map = new Our.Umbraco.GMaps.Models.Map
    {
        Address = new Our.Umbraco.GMaps.Models.Address
        {
            Coordinates = $"{googleAddress.Coordinates.Latitude.ToString(CultureInfo.InvariantCulture)}, {googleAddress.Coordinates.Longitude.ToString(CultureInfo.InvariantCulture)}",
            FullAddress = googleAddress.FormattedAddress,
            PostalCode = store.Zip,
            City = store.City,
            State = "",
            Country = store.CountryName
        }
    };

    var mapJson = Newtonsoft.Json.JsonConvert.SerializeObject(map);

    // Store JSON in GMaps property editor
    node.SetValue(ContentModels.Store.GetModelPropertyType(_publishedSnapshotAccessor, x => x.Location).Alias, mapJson);
}

_contentService.SaveAndPublish(node);

The Address and Coordinates properties are set here:

// Defaults.
Address = new Address();
MapConfig = new MapConfig();

Coordinates = new Location();

It would probably make sense to add overload of these, e.g. to pass in coordinates to constructor new Location(lat, lng) or to use literal notation.