GPS like tool in SAP using Google Map API

GPS like tool in SAP
Share on Facebook37Share on LinkedIn36Tweet about this on TwitterShare on Google+0
Please Share!!

In the earlier article, we saw how we can get the latitude and longitude of any address using Google Map API. Adding to that learning, in this post, we would learn how to get the distance between two addresses. We would also see how we can derive turn by turn directions between two given addresses. To add more to the fun, we would also open a browser from SAP and display the route between two points on the map.

Do you think, this is interesting? 🙂

In short, this tool would act like a GPS in SAP, which would help you get the Coordinates (Latitudes/Longitudes), Route and Map with complete direction.

Before we check, how it can be done, let us first see, what we are talking about.

I.  First radio button: Coordinates & Distance

Latitude and Longitude

We get the Coordinates of two addresses and also the distance between them.

Latitudes and Longitudes in ABAP

II.  Second Radio button: Turn by turn route

GPS Route in SAP

The tool would provide you the complete break-up of the route from the source to the destination address. It would also provide you with multiple routes if available.

Turn by turn direction and route

II.  Let’s check the third radio button which says ‘Display Map‘.

Display Map

As requested, this GPS Tool would display the map along with the routes in a Web Browser. Check this out.

Google Map

 

Also Read: SAP ABAP on HANA. Part I : Create your first program in HANA Studio.

Did you like it?

You can use the  code snippet provided at the end of this article and try it yourself. The code provided here would work as it is. The concept was already explained in our earlier post ‘Get Latitude and Longitude of any place using Google Map API in SAP’.

For the three output options, we need to call three APIs. As explained in the earlier article, we concatenate the strings with source and destination address, Latitudes and Longitudes etc to complete the API URL and get the XML data. Reading through the XML data and pinpointing the needed information is the trick which we have already learned.

a) GeoCode API String for Coordinates:

b) Distance Matrix API String for retrieving the distance between Coordinates:

c) Directions API String to trace the route on the Map:

where:
lv_address               = From/To address
<fs_dest>-place_f = From address
<fs_dest>-lat_f      = From address latitude
<fs_dest>-lng_f     = From address longitude
<fs_dest>-place_t = To address
<fs_dest>-lat_t      = To address latitude
<fs_dest>-lng_t      = To address longitude

Once you have the correct API URL, use this cl_http_client class and create_by_url method to get the detailed information.

Please go through the detailed code to check how it works. There might be better ways to read these APIs and XML data but we just wanted to show the possibilities. You can explore more and figure out the best way for you.

If you find any difficulty in understanding the code or concept, please do write to us or leave your question in the comment section. We would surely respond.

If you have doubt whether this tool would work for Non-India address. Be rest assured, it works for any address. Check the output for the address in the USA. 🙂

7

Also Check: SAP HANA from Space Level.

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 Facebook37Share on LinkedIn36Tweet 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.

20 Comments on "GPS like tool in SAP using Google Map API"

  1. Heleno Andrade | November 21, 2016 at 8:02 pm | Reply

    Hi Experts.

    The p_http_client->receive method is returning error 1 (http_communication_failure). What could be happening? Does this functionality not work in the development environment? Thanks!

  2. Wow! impressive. What is the license requirements for using the GOOGLE API for business?

  3. Hi Experts,
    To use Google Geo coding in SAP.I have written program to consume Google Geocode API via HTTP send/receive.But Http response is Application server error.

    Kindly help on the same

    URL for Accessing Google API – http://maps.google.com/maps/api/geocode/xml?address=Newyork,USA

    Regards,
    Uma

  4. HI Experts,
    When i execute the program am getting the response ‘Application Server Error’.Can you please let me know the required system setup before executing this program.

  5. Hi,

    i have create same program in ecc-6.0 0 patch level. Its not work, did i need to install or used any odata or hana services for the same or not.

    • Dear Sonu – We are in the most recent patch. So may be some structures/types may not be there in your version? What is the error you are getting?

      One reader reported error: Type “HRPAYFR_T_SMUM_XMLTB” is unknown.

      If you are also getting the same error, then please create a custom (Z) Table Type of structure “smum_xmltb” and replace it where TYPE HRPAYFR_T_SMUM_XMLTB is being used.

      Please let us know what error you are getting. We would try to help you out.

      Regards,
      Team SAPYard

  6. venubabu divvi | June 2, 2016 at 3:33 pm | Reply

    Thank you Kuldeep.
    Thanks you SAP YARD too, you guys done great job, it helps me lot. Yesterday only i raised request for this in other blog of yours. Today i got the solutions..simply awesome job.

    Thanks,
    Venubabu Divvi

    • Kuldeep Joshi KULDEEP JOSHI | June 3, 2016 at 7:27 am | Reply

      YOUR WELCOME 🙂 also thanks to raju he appriciated and make this code published in sapyard .com, we can use this code to integrate other google api .

      • Dear Kuldeep – On behalf of SAPYard and our readers, we would like to thank you for this wonderful share. Our readers are loving it. Do keep on sharing interesting and new findings and help our readers.

        Regards,
        Team SAPYard.

    • You are welcome Divvi. Thanks to Kuldeep who is the brain behind this post.

      We are so happy to learn that you got solution so quickly.

      Happy learning!!

      Team SAPYard.

  7. Thanks, Team SAPYard.

    Issue has been resolved! As suggested, I created a custom table type of structure “smum_xmltb” and replaced it with HRPAYFR_T_SMUM_XMLTB.

  8. Great work Kuldeep Joshi!

    Tried code from your previous blog post(http://www.sapyard.com/get-latitude-and-longitude-of-any-place-using-google-map-api-in-sap/). Worked flawlessly.

    Trying to execute code from this blog and getting error: Type “HRPAYFR_T_SMUM_XMLTB” is unknown.

    (Using release EHP7 FOR SAP ERP 6.0)

    Do we have to install any additional component/package/module to run this code?

    • Dear ZSK – Thank you so much for taking some time off and writing to us.

      No, you do not need to install any additional thing.

      * The below line is giving error for you.
      CHANGING p_li_xml_table TYPE hrpayfr_t_smum_xmltb.

      Seems table type HRPAYFR_T_SMUM_XMLTB, is not there in your SAP system. You can create a custom (Z) Table Type of structure “smum_xmltb”. And use it in place of HRPAYFR_T_SMUM_XMLTB.

      Or else, for testing, define li_xml_table TYPE TABLE OF smum_xmltb as global internal table. And remove it from CHANGING parameters. In that case, you do not need the table type HRPAYFR_T_SMUM_XMLTB.

      Let us know, if you still face issue.

      Regards,
      Team SAPYard.

  9. Just Awesome.. Keep it up good work..

Leave a Reply to ZSK Cancel reply

Your email address will not be published.


*