Get Visitor Location(lat/long) Using Geolocation in Any Application

Опубликовано: 25 Октябрь 2024
на канале: Tech Probie
1,365
10

Blog Link: https://thapliyalravi80.blogspot.com/...

#Geolocation #javascript #API #google console #tutorials #geolocationAPI
*****JS Code ****
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition, showError);
} else {
alert("Geolocation is not supported by this browser.");
}
}

function showPosition(position) {
apex.item("PAGE_ITEM_LAT").setValue(position.coords.latitude)
apex.item("PAGE_ITEM_LONG").setValue(position.coords.longitude)
function geocode_api(){
var latitude = position.coords.latitude
var longitude = position.coords.longitude
var key = "API_KEY"
$.post('https://maps.googleapis.com/maps/api/..., //get this line code from comment section and replace it with this line as in description it is taking it as link.

function(data, status){
var address = JSON.parse(JSON.stringify(data.results[0].formatted_address))

apex.item("PAGE_ITEM_LOCATION").setValue(address)

// alert("Data: " + data + "\nStatus: " + status);
});
};
geocode_api();
}

function showError(error) {
switch(error.code) {
case error.PERMISSION_DENIED:
alert("User denied the request for Geolocation.")
break;
case error.POSITION_UNAVAILABLE:
alert("Location information is unavailable.geolocation app tutorial, geolocation, javascript, location")
break;
case error.TIMEOUT:
alert("The request to get user location timed out.")
break;
case error.UNKNOWN_ERROR:
alert( "An unknown error occurred.")
break;
}
}

razorpay payment gateway integration || payment gateway for website
   • razorpay payment gateway integration ...  

Shopify API Tutorial | Shopify tutorial for beginners || Shopify API get all products || postman API
   • shopify API Tutorial | shopify tutori...  

PayPal smart payment button for website | PayPal account Kaise banaye | PayPal business account
   • How to create paypal account  | How t...  

oracle apex tutorial for beginners in hindi || step-by-step from starting || oracle apex ✔️
   • oracle apex tutorial for beginners in...