'How can I retrieve the location coordinates from a WhatsApp location share?

I am building a Node.js application that receives messages from WhatsApp via Twilio. Sending text messages is not a problem, but when I try to send the current location from the users WhatsApp account I cannot find the coordinates in the request object sent to the server.

This is what I am doing to see what is being sent to the app from Twilio.

app.post('/incoming', (req, res) => {
var incomingMessage = req.body.Body;
console.log(incomingMessage); });

When I share my current location with the app, the request body is empty.

Can anyone shed any light on this or explain how WhatsApp shares a users location within the app?

Thanks.



Solution 1:[1]

Here it says is it possible to recieve location data on the Body: https://www.twilio.com/docs/whatsapp/api#location-messages-with-whatsapp

You can also receive inbound location messages with the Twilio API for WhatsApp. Locations will not show up in the Twilio Console at this time. However, your web application will receive the location data in the POST request that Twilio sends. Below is a sample payload containing location information. Please note that the Body={name} parameter is not required for inbound messages.

Latitude=37.7879277&Longitude=-122.3937508&Address=375+Beale+St%2C+San+Francisco%2C+CA+94105&SmsMessageSid=SMxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&NumMedia=0&SmsSid=SMxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&Label=Twilio+Inc&Body=&To=whatsapp%3A%2B14155238886&NumSegments=1&MessageSid=SMxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&AccountSid=ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&From=whatsapp%3A%2B12345678900&ApiVersion=2010-04-01

Solution 2:[2]

At the moment it is possible to send to the user some location but you can't get user location directly through twilio whatsapp api. https://www.twilio.com/blog/send-location-details-whatsapp-node-js.

Solution 3:[3]

Update your code with:

var incomingMessage = req.body;

Twilio supporting both sending and receiving location. The below one is the response of the location when a user sends from his WhatsApp to the Twilio WhatsApp.

{
"Latitude": "24.7969323",
"Longitude": "46.6301663",
"SmsMessageSid": "xxxxxxxxxxxxxxxxxxxxxx",
"NumMedia": "0",
"SmsSid": "xxxxxxxxxxxxxxxxxxxxxx",
"SmsStatus": "received",
"Body": "",
"To": "whatsapp:+1415xxxxxxx",
"NumSegments": "1",
"MessageSid": "xxxxxxxxxxxxxxxxxxxxxx",
"AccountSid": "xxxxxxxxxxxxxxxxxxxxxx",
"From": "whatsapp:+966xxxxxxxxxxxxxxxxxxxxxx",
"ApiVersion": "2010-04-01"

}

Here you can see the Latitude and Longitude of the user.

Solution 4:[4]

I solved the issue by installing Google Earth on the same phone. Then I clicked the WhatsApp location share, and opened it with Google Earth.

Google Earth showed the coordinates in geographic degrees, minutes and seconds.

Solution 5:[5]

Go to Your Phone Menu.

Find WhatsApp.

Tap on the WhatsApp Icon.

Make Sure That, You Are on the Chats Tab.

Tap on the “Group” or “Individual Chat” Where You Want to Share Your Live Location.

Tap on the “Attach Icon”.

Tap on the “Location”.

Tap on the “Share Live Location

Solution 6:[6]

Simply prompt user to open a company webpage that contains Javascript that capture user's location You can read more detail in here: https://ma-zamroni.medium.com/workaround-for-whatsapp-business-api-to-get-customers-current-location-392c63b4b365

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Rucc
Solution 2 specter epiphane
Solution 3 joe
Solution 4 Abs
Solution 5 nnamdi igwe
Solution 6 Mochamad Aris Zamroni