Ticker

6/recent/ticker-posts

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

How to get Latitude and Longitude in Oracle Apex

In this Oracle APEX Tutorial, I will explain with an example that how to get latitude and longitude in oracle apex.

What are 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.

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 location or 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

You can also watch (how to get latitude and longitude in oracle apex) video on my youtube channel.

Post a comment

0 Comments