Mr.D Mr.D - 2 years ago 119
Javascript Question

Facebook Messsenger, how to handle sent location

According to this guide, it describes us to how to send messages and handle buttons texts etc.

However, when users sends to bot its

, my webhook receives it as this:

{ sender: { id: 99999999999999},
recipient: { id: 99999999999999 },
timestamp: 99999999999,
{ mid: 'mid.9999999:999999999',
seq: 231,
attachments: [ [Object] ] } }

Location is sent to webhook as some kind of object inside

When in my code I try to get them like this:


I get

How to get longitude and latitude of Location that user has sent? There is no description of this in documentation.


After some trying I was able to get all its properties. When users sents their location I get it in this structure:


It is GIANT URL. If you open this link via your browser, it will open Bing Maps and shows this location.

It is hard to work with this data. It forces users to write their own parsers.

Answer Source

Latitude and Longitude are there in the URL:


So one way would be to convert the URL to text and just parse this text to get Lat and Long.

UPDATE Now lat and lng can be directly accessed from the attachments JSON:

lat = event.message.attachments[0]
lng = event.message.attachments[0].payload.coordinates.long
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download