How to save a CLLocation with Cloudkit JS

115 Views Asked by At

I'm using Cloudkit JS to save data to a public database. Its easy to do when the fields are all strings. I'm stuck now trying to figure out how to save data when the field type is a CLLocation. Somehow I need to structure the JavaScript to send both latitude and longitude values.

See the ??? in the code example below;

var new record = { recordType: "Thing",
    fields: {   name: { value: "My Name" },
                description:  { value: "My Description" },
                location: { ??? }
    }
};

Does anyone know how to take the lat and long coordinates and represent them in the code above?

1

There are 1 best solutions below

1
On BEST ANSWER

Try passing it like this:

fields: {
    location: { value: { latitude: lat, longitude: lng }, type: "LOCATION" }
}

lat and lng are Doubles, not Strings