How to copy latitude and longitude fields in GeoPoint on Parse.com

I imported 16,000 csv lines to the Parse.com class. Now I need to convert the latitude and longitude fields to a field of the Parse.com GeoPoint data type.

I added a GeoPoint field and now I have to start the update to copy the lat / lng data from each line into the corresponding GeoPoint field.

Where in the API or Parse.com did the user do this? I can't seem to find him. I know that this is possible because what a normal development team will omit such a function.

+3
source share
1 answer

The solution is to really create a Job using CloudCode. Here is an example in Javascript:

Parse.Cloud.job("airportMigration", function(request, status) {
    // Set up to modify user data
    Parse.Cloud.useMasterKey();

    var recordsUpdated = 0;

    // Query for all airports with GeoPoint location null
    var query = new Parse.Query("Airports");
    query.doesNotExist("location");
    query.each(function(airport) {
        var location = {
            latitude: airport.get("latitude_deg"),
            longitude: airport.get("longitude_deg")
        };
        if (!location.latitude || !location.longitude) {
            return Parse.Promise.error("There was an error.");
            // return Parse.Promise.resolve("I skipped a record and don't care.");
        }

        recordsUpdated += 1;
        if (recordsUpdated % 100 === 0) {
            // Set the job progress status
            status.message(recordsUpdated + " records updated.");
        }

        // Update to GeoPoint
        airport.set("location", new Parse.GeoPoint(location));
        return airport.save();
    }).then(function() {
        // Set the job success status
        status.success("Migration completed successfully.");
    }, function(error) {
        // Set the job error status
        console.log(error);
        status.error("Uh oh, something went wrong.");
    });
});
+4
source

All Articles