google-maps-api-3telegram-bot

Send google maps location given address via Telegram


I'm coding a Telegram Bot with Python and I'm using Google Maps Geolocation API to find different addresses. I have JSON Object with a formatted_address field, which contains the exact address of the location correctly formated, for example: 100 Green Hwy, Mattapan, MA 02122, USA.

I'd like to send the location to a chat conversation, something like this:

Location sample image

Or at least, generate a google maps link which points to the location, so the other people in the chat can open the link using google maps or the browser.

So just to make it clear, I want to send the location message to a Telegram chat conversation given 100 Green Hwy, Mattapan, MA 02122, USA or its coordinates (if it's possible to find them), or at least send a link which would look similiar to this one: https://maps.google.com/location/100+Green+Hwy+Mattapan+MA (note that I just made it up, and this won't work).


Solution

  • I finally was able to do it using the Geolocation API. I made this requests

    https://maps.googleapis.com/maps/api/geocode/json?address=HERE_THE_FULL_ADDRESS_AND_CITY&key=MY_API_KEY 
    

    I got a JSON response (which contained the Latitude and Longitude inside the Geometry key. Then, I used the sendLocation function of the Telegram Bot API, to send the coords.