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

    Sales Office Data … Can you change it even if config does not allow?

    Your business needs to change/right the Business Office information, regardless of whether it isn’t permitted in standard change mode in exchange IW32. See the screen capture, it is incapacitated. Sales…

    PO re-price issue in BAPI_PO_CHANGE

    PO re-price issue in BAPI_PO_CHANGE. BAPI_PO_CHANGE is utilized for re-estimating the Buy Request. The computation type CALCTYPE ought to be set to ‘B’ (signifying ‘Complete new valuing’) and PRICEDATE ought…

    Leave a Reply

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

    You Missed

    Sales Office Data … Can you change it even if config does not allow?

    • By Varad
    • April 15, 2025
    • 21 views
    Sales Office Data … Can you change it even if config does not allow?

    PO re-price issue in BAPI_PO_CHANGE

    • By Varad
    • April 14, 2025
    • 27 views
    PO re-price issue in BAPI_PO_CHANGE

    Efficient way to retrieve Open Sales Order using FM SD_SELECT_SALES_DOCUMENTS

    • By Varad
    • April 13, 2025
    • 32 views
    Efficient way to retrieve Open Sales Order using FM SD_SELECT_SALES_DOCUMENTS

    ISU – 6 – Bankruptcy Overview and Write-Off Process using BAPI_CTRACDOCUMENT_WRITEOFF

    • By Varad
    • April 12, 2025
    • 31 views
    ISU – 6 – Bankruptcy Overview and Write-Off Process using BAPI_CTRACDOCUMENT_WRITEOFF

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

    • By Varad
    • April 11, 2025
    • 31 views
    Get Latitude and Longitude of any place using Google Map API in SAP

    Real Time Exchange Rate with Real Time Data Using Yahoo Finance API

    • By Varad
    • April 10, 2025
    • 39 views
    Real Time Exchange Rate with Real Time Data Using Yahoo Finance API