Get Latitude and Longitude of any place using Google Map API in SAP

Share on Facebook109Share on LinkedIn58Tweet about this on TwitterShare on Google+0
Please Share!!

SAP surprises us every day. Even after working for more than a decade, a new project or client will have some requirements which are unique and you need out of the box thinking and solution. The below post is a similar requirement where a client wanted to know the Geo Coordinates of any given place. There are many ways to get the Latitudes and Longitudes but Kuldeep Joshi (who contributed this post), found a very convenient way by using Google Map API. He thought Google Map is free and readily available, so why not use it in SAP with ease.

Check below, if the user enters any address, he should get the latitude and longitude of that place.

Geo Coordinates in SAP

Isn’t it a cool requirement?

How can we achieve this?

Simple, connect to Google Map Service (read API), scan through its content string and find your data. It needs some reading through the string, but this is really effective and easy solution.

Check this steps (detailed code is available at the end of the article below)


Concatenate your input address with the Google Maps API web address to get the client data.

Generate Google Map API path

You might like to read the next related article: GPS like Tool in SAP.

Request the data. Check your cases (lower/upper) of the methods (they might be case sensitive).

Get Method

Send the request.

Request service

Receive the response from Google API.

Receive the request

Now, you have the string content. Just look through the string at the right place and get the latitude/longitude information.

Geo Code from Google Map API

<location> </location> are the opening and closing tag. We need to find the latitudes and longitudes in between these two tags.

Check API code

Similarly <lat> </lat> and <lng> </lng> are the opening and closing tags for Latitude and Longitude respectively.

This is one example of the content file received from Google API. Looking at the data, it is very clear, where we can find the coordinates.

Google API

Hopefully, this post would help you to find the required coordinates. In the next post, Kuldeep would show how to find the distance between two addresses using Google API in SAP. Also, he would show, how to open the two addresses in Google Map and show the distance in the browser. Please stay tuned.

And our code not only works for India address, it works for any address in the world. Let’s check an address in USA. 🙂

Coordinates in SAP ABAP

You can validate the coordinates in Google Map manually.

Also Read: Unix file in SAP.

Here is the code snippet used for this post.

If you want to get such practical issues and resolutions straight to your inbox, please SUBSCRIBE. We respect your privacy and take protecting it seriously.

If you liked this post, please hit the share buttons.

Thank you very much for your time!!

Share on Facebook109Share on LinkedIn58Tweet about this on TwitterShare on Google+0
Please Share!!

About the Author

Kuldeep Joshi
Kuldeep Joshi

Kuldeep Joshi is an Electronics Engineer graduate. He has more than 7 years of experience in SAP with specialization in ABAP. He is an ex-IBMer who also has good working experience in SAP BI BPC.

Find more about him on LinkedIn.

26 Comments on "Get Latitude and Longitude of any place using Google Map API in SAP"

  1. Hi Kuldeep,

    I am getting exception “http_communication_failure” for below lines of code, what could be the reason?

    * Reterive the result
    CALL METHOD p_http_client->receive
    http_communication_failure = 1
    http_invalid_state = 2
    http_processing_failed = 3
    OTHERS = 4.

    Swapnil Joshi

    • Dear Swapnil – We doubt some service is not active in your system or it is authorization issue.

      Can you check with your Basis/Security team and ask if they have some answer.

      Did you use our code or did you write your own code? If you have different code, please share with us and we would be happy to check it in our system.

      Team SAPYard.

  2. Congratulations!! Great JOB!

  3. Mani Nagarajan | August 1, 2016 at 9:28 pm | Reply

    Good Blog Indeed, it would be nice if we get lat long with out entering Address.
    Like in Google maps, Just click any spot and get coordinates.

  4. Michael Smith | June 23, 2016 at 1:35 pm | Reply

    Does Google require you to purchase an API Key before using these services in productive code?

  5. Kuldeep Joshi Kuldeep Joshi | June 16, 2016 at 6:14 am | Reply

    Thanks everyone?and thanks to raju

  6. Satish Gupta | June 14, 2016 at 5:32 am | Reply

    This is great Kuldeep.I am sure you must be developing many more for making the work simpler.
    Congratulation and keep it up.

    • Dear Satish – On behalf of Kuldeep, SAPYard Team would like to thank you for taking some time off and providing your feedback.

      We are glad that it made your work simpler.


  7. Benedict John Torres | June 2, 2016 at 7:17 am | Reply

    This is great. you can also try translate API. It can be useful for multi-language transactions or notes / comments.

    “data”: {
    “translations”: [
    “translatedText”: “Hallo Welt”

    • Thank you Benedict. Can you please show how to use it? We and our readers would be benefitted with this info. I tried the link you provided, but could not understand the output.

      Team SAPYard.

  8. venubabu divvi | June 1, 2016 at 2:01 pm | Reply

    Great Job, This program helps me a lot, now i need to understand how this will get the data.


    • Dear Venu – We are happy to know that our post helped you. To understand how data is being pulled, put a break point after the string is retrieved from API.

      Do let us know if you face any issue.

      Team SAPYard.

      • venubabu divvi | June 1, 2016 at 3:26 pm | Reply

        Yes I did that, i got the logic how it works..i think we can use this program to get multiple places also.
        Now i am looking for calculate miles between two different places in ABAP.
        Please suggest me if you have any logic to find miles between two places using Maps.

        Venubabu Divvi

        • Dear Divvi – Glad that our post was able to help you in actual need. Plese check our next post, GPS like Tool in SAP. You should find the solution for your need to calculate distance between two places.

          All the best.

          With Regards,
          Team SAPYard.

  9. good job man

  10. This is great staff. Thank you so much raju

  11. This requirement was one of a kind 🙂 Thumbs up !

  12. ermal lushi | May 27, 2016 at 6:16 am | Reply

    This was great.

Leave a Reply to SAP Yard Cancel reply

Your email address will not be published.