parse-platformparse-javascript-sdkparse-cloud-code

parse server - how to extract longitude+latitude from ParseGeoPoint in cloud code


In cloud code, I want to get the longitude and latitude from a geopoint that was stored in the DB.

This is some of what I see in the logs - for afterSave function

2019-03-24T13:41:01.130Z - afterSave triggered for abc for user XYZ:
_ Input: {“geo”:{"__type":“GeoPoint”,“latitude”:32.7843083,“longitude”:34.6441017},“image”:_

In an afterSave cloud function - I’m reading the geoPint itself by calling:

const geo = request.object.get(“geo”);

But how do I get the longitude & latitude from the geo constant?


Solution

  • In your afterSave function add the following const for your geoPoint:

    const geo = request.object.get("geo");
    

    and then, simply refer to:

    geo.latitude
    

    and

    geo.longitude
    

    The same works in any environment running the Parse JavaScript SDK (but your variable declaration would be different).