Click here to Skip to main content
15,908,776 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to display latitude and longitude using Modnizer geolocation api.
In my java script code when i try to execute my web application with the code.

JavaScript
if (Modernizr.geolocation ) {
    // Find location... fill in.
    //alert(" inside Modernizer");
    // Not coming here if i use if(Modernizr.geolocation)

     navigator.geolocation
    .getCurrentPosition(location_found, location_error);

}


Nothing happens when i press the set location button. but when i try to execute the web application without

JavaScript
if (Modernizr.geolocation )
{
}


I get the latitude and longitude displayed on the web page. y the control is not passing from the if (Modernizr.geolocation ) statement .
Posted

See https://modernizr.com/docs[^]

Quote:
Geolocation API geolocation
Detects support for the Geolocation API for users to provide their location to web applications.


If the browser does not support it or if you choose block when asked by the browser it will return false.
 
Share this answer
 
I'd rather use HTML5 [^] feature of geolocation.
JavaScript
function getLocation() {
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(showPosition);
    } else {
        x.innerHTML = "Geolocation is not supported by this browser.";
    }
}
function showPosition(position) {
    alert("Latitude: " + position.coords.latitude + 
    ", Longitude: " + position.coords.longitude); 
}


-KR
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900