SAP GPS-like tool with Google Map API

We learned how to use the Google Map API to obtain the latitude and longitude of any address. To supplement that knowledge, we would discover how to calculate the distance between two addresses in this post. Additionally, we would examine how to determine the turn-by-turn directions between two provided addresses. We would also launch a SAP browser and plot the path between two locations on a map to increase the pleasure.

Is this fascinating, in your opinion? 🙂

In a nutshell, this tool would work in SAP much like a GPS, allowing you to get coordinates (Latitudes/Longitudes), a route, and a map with comprehensive directions.

The first radio button: Distance & Coordinates

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

II.  Second Radio button: Turn by turn route

You would receive a comprehensive breakdown of the route from the source to the destination address from the tool. If accessible, it would also give you several paths.

II. Let’s select the “Display Map” radio button, which is the third one.

This GPS Tool would show the map and the routes in a web browser as asked. Look into this.

Google Map

Did you find it enjoyable?

You can try it out for yourself by using the code snippet that is provided at the conclusion of this post. This code would function just the way it is.

We must make three API calls in order to get the three output options. As previously mentioned, in order to finish the API URL and obtain the XML data, we concatenate the strings with the source and destination addresses, latitudes, longitudes, etc. We already know the trick: scanning the XML data and identifying the information that is required.

a) Coordinate GeoCode API String:

* Prepare the url of the GeoCode API
  CONCATENATE
    'http://maps.google.com/maps/api/geocode/xml?address='
    lv_address
    INTO lv_http_url .

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

* Prepare the url for the DistanceMatrix API using From Address Coordinates and To Address Coordinates
  CONCATENATE
    'http://maps.googleapis.com/maps/api/distancematrix/xml?origins='
    <fs_dest>-place_f '|' <fs_dest>-lat_f ',' <fs_dest>-lng_f ','
    '&destinations=' <fs_dest>-place_t '|' <fs_dest>-lat_t ',' <fs_dest>-lng_t
    '&alternatives=' 'true'
    INTO lv_http_url .

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

* Prepare the url for Directions API for the From Address Coordinates and To Address Coordinates
  CONCATENATE
    'http://maps.googleapis.com/maps/api/directions/xml?origin='
    <fs_dest>-place_f '|' <fs_dest>-lat_f ',' <fs_dest>-lng_f
    '&destination=' <fs_dest>-place_t '|' <fs_dest>-lat_t ',' <fs_dest>-lng_t
    '&alternatives=' 'true'
    INTO lv_http_url .

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

Use this cl_http_client class and the create_by_url function to obtain the detailed information after you have the relevant API URL.

* Get client from url
  CALL METHOD cl_http_client=>create_by_url
    EXPORTING
      url                = lv_http_url
    IMPORTING
      client             = p_http_client
    EXCEPTIONS
      argument_not_found = 1
      plugin_not_active  = 2
      internal_error     = 3
      OTHERS             = 4.

Please review the detailed code to see how it functions. We merely intended to illustrate the options. There may be more efficient ways to read these APIs and XML data. You can investigate further to determine the best course of action.

Please feel free to contact us or ask a question in the comment section if you need help understanding the code or an idea. Without a doubt, we would react.

Would you kindly click the share buttons if you enjoyed this post?

I sincerely appreciate your time!


you may be interested in this blog here:-

How Many Employees Does Salesforce Have in 2024?

Role of SAP Consultants in Modern Business Transformations

Advanced Code Snippet Techniques : Mastering the Craft

  • Related Posts

    How Can UI5 Apps Be Deployed Without LPD_CUST?

    Applications using SAPUI5 have the option to include reusable UI blocks known as Components. These are SAPUI5 applications that are completely working. Put differently, SAPUI5 apps can leverage the notion…

    SAPUI5: Fundamental Factory Functions for Freshmen

    Do you count among those who are just now becoming aware of Factory functions? Do not experience exclusion. Few people are familiar with this word. Everyone is growing and learning…

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    You Missed

    How Can UI5 Apps Be Deployed Without LPD_CUST?

    • By Varad
    • February 20, 2025
    • 28 views
    How Can UI5 Apps Be Deployed Without LPD_CUST?

    SAPUI5: Fundamental Factory Functions for Freshmen

    • By Varad
    • February 19, 2025
    • 35 views
    SAPUI5: Fundamental Factory Functions for Freshmen

    Utilizing the Formatter Function in SAPUI5

    • By Varad
    • February 18, 2025
    • 34 views
    Utilizing the Formatter Function in SAPUI5

    SAPUI5, the newly introduced Resource Model

    • By Varad
    • February 17, 2025
    • 53 views
    SAPUI5, the newly introduced Resource Model

    How can I send an email in the SAPUI5 Hybrid App? Advance SAPUI5 – 3.

    • By Varad
    • February 16, 2025
    • 50 views
    How can I send an email in the SAPUI5 Hybrid App? Advance SAPUI5 – 3.

    Advanced Speech Recognition with SAPUI5–7

    • By Varad
    • February 15, 2025
    • 43 views
    Advanced Speech Recognition with SAPUI5–7