Ticker

6/recent/ticker-posts

How to get Latitude and Longitude in Oracle APEX - Javainhand Tutorial

In this Oracle APEX Tutorial post, We will explore about the how to get Latitude and Longitude in Oracle APEX.

How to get Latitude and Longitude in Oracle Apex

Before we will go ahead in this post, we have to know about the Latitude and Longitude.

What is Latitude and Longitude?

Latitude and Longitude are a system of lines used to describe the location of any place. 

Click Here For More About the Latitude and Longitude.

Important Notes:-

Geolocation API will work only on the secure network(HTTPS). So If you are trying to implement get user location information like latitude and longitude in Oracle APEX then be sure that you are work on the secure network(HTTPS).

If you are not working on the secure network then try on the localhost environment because browser consider localhost as a secure network.

How to Get Latitude and Longitude in Oracle APEX?

Basically, I am using the GEOLOCATION API to getting the user's current Latitude and Longitude. The follow below steps and you can easily implement in your Application.

  1. Create a Region with three Items P15_LATITUDE, P15_LONGITUDE, and P15_ERROR. Below Screenshot will help you out.

    How to get Latitude and Longitude in Oracle Apex
  2. Now Create getLocation() Function in Function and Global Variable Declaration.The below code will help you.
  3. function getLocation() {
    var x=document.getElementById("P15_ERROR");
    if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(
     function setPosition(position) {
     //x.innerHTML="setPosition:"+position.coords.latitude;
     $s("P15_LATITUDE" , position.coords.latitude);
    $s("P15_LONGITUDE", position.coords.longitude);
     }
    ,function (error)
    {
    switch(error.code) 
    {
    case error.PERMISSION_DENIED:
    x.innerHTML="User denied the request for Geolocation."
    break;
    case error.POSITION_UNAVAILABLE:
    x.innerHTML="Location information is unavailable."
    break;
    case error.TIMEOUT:
    x.innerHTML="The request to get user location timed out."
    break;
    case error.UNKNOWN_ERROR:
    x.innerHTML="An unknown error occurred."
    break;
    }
    }    
    ,{timeout:10000});
    x.innerHTML="Success";
    }
    else
    x.innerHTML="Geolocation is not supported by this browser.";
    }

  4. Now Create a Page Load Dynamic Action for Call Above Function. The below screenshot will help you.

    Oracle APEX Tutorial - How to get Latitude and Longitude in Oracle Apex
  5. If you do not Allow Location Tracing Popup then it will give an error in p_error Item.

That's all for today, If you like the (how to get latitude and longitude in oracle apex) post then share valuable comments in the comment section.

Reference
https://www.w3schools.com/html/html5_geolocation.asp

Click Here

Watch Video for Implementing Latitude and Longitude in Oracle APEX

Post a comment

0 Comments