How to send location from Facebook messenger platform?

≡放荡痞女 提交于 2019-11-28 21:35:36
Dmitry

There is workaround. We can send generic template with static map image and url to dynamic. For iOS native map app we can use address http://maps.apple.com/maps (which redirects all non iOS users to Google Maps with the same parameters). On Android it opens Google Maps app.

{
    "recipient": {"id": "132456"},
    "message": {
        "attachment": {
            "type": "template",
            "payload": {
                "template_type": "generic",
                "elements": {
                    "element": {
                        "title": "Your current location",
                        "image_url": "https:\/\/maps.googleapis.com\/maps\/api\/staticmap?size=764x400&center="+lat+","+long+"&zoom=25&markers="+lat+","+long,
                        "item_url": "http:\/\/maps.apple.com\/maps?q="+lat+","+long+"&z=16"
                    }
                }
            }
        }
    }
}

Dmitry, thanks for the hack! FB API has slightly changed, here's what worked for me in the payload section:

    payload = dict()
    payload['type'] = 'template'
    payload['text'] = dict(
        template_type="generic",
        elements=[
            dict(
                title='{venue} location',
                # subtitle='Test',
                image_url="https://maps.googleapis.com/maps/api/staticmap?size=764x400&center=" + lat + "," + long +
                          "&zoom=15&markers=" + lat + "," + long,  
                default_action=dict(
                    type="web_url",
                    url="http://maps.apple.com/maps?q=" + venue + "&ll=" + lat + "," + long +
                        "&z=15"
                )
            )  # buttons=[])
        ]
    )
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!