Hi there I am new to javaScript. What I would like to do is get the users location and save it as a geoPoint to my parse.com database. I have searched their docs and worked out the basics of how to do it but need a little help. I am getting the geoPoint by performing the following:

var point = new Parse.GeoPoint.current;

and trying to save it by performing:

testObject.set("geoPoint", point);

In my geoPoint column on parse.com it gets saved as {"_rejected":false,"_rejectedCallbacks":[],"_resolved":false,"_resolvedCallbacks":[]}

I'm assuming this is because the location is attempting to be saved before the location has actually been found.

So my question is how do I wait until the location is found before sending it to parse?

In the parse docs they say to use Parse.GeoPoint.current(options)

but I'm not too sure how to go about this options part. I'm really hoping someone can give me some sample code on how to use options.success

Thanks for your time!

有帮助吗?

解决方案

Parse.GeoPoint.current(options) Creates a GeoPoint with the user's current location, if available. Calls options.success with a new GeoPoint instance or calls options.error. Parameters: {Object} options An object with success and error callbacks. - https://www.parse.com/docs/js/symbols/Parse.GeoPoint.html

Bascially, you can do:

Parse.GeoPoint.current({
    success: function (point) {
        //use current location
        console.log(point);
    }
});
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top