Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I am getting (lat,long) coordinates in phonegap geolocation without using internet or GPS ?

When i tried out a sample program in phonegap geolocation. I am getting the latitude and longitude of my current location without internet or GPS in my samsung pop. I don't know how it is getting the coordinates, altitude and timestamp of the current location when the wifi and gps in my device is DISABLED. Kindly help me..

   <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org    /TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
        <title>My Locator</title>
        <script type="text/javascript" charset="utf-8" src="../plugins/phonegap-1.1.0.js"></script>
        <script type="text/javascript" charset="utf-8">
            document.addEventListener("deviceready", onDeviceReady, false);
            function onDeviceReady() {
                navigator.geolocation.getCurrentPosition(onSuccess,Error);
            }
        function onSuccess(position) {
                var element = document.getElementById('geolocation');
            element.innerHTML = 'Latitude: ' + position.coords.latitude 
                + '<br />' + 'Longitude: ' + position.coords.longitude 
                + '<br />' + 'Accuracy: ' + position.coords.accuracy 
                + '<br />' + 'Timestamp: ' + new Date(position.timestamp)  + '<br />';

            }
        function onError(error) {
                alert('code: ' + error.code + '\n' + 'message: ' + error.message + '\n');
            }

        </script>
    </head>
    <body>
        <p id="geolocation">
            Finding geolocation...
        </p>
    </body>
</html>
like image 904
Firnaz Avatar asked Jan 17 '23 18:01

Firnaz


2 Answers

"Common sources of location information include Global Positioning System (GPS) and location inferred from network signals such as IP address, RFID, WiFi and Bluetooth MAC addresses, and GSM/CDMA cell IDs."

http://docs.phonegap.com/en/1.7.0/cordova_geolocation_geolocation.md.html#Geolocation

like image 149
gmh04 Avatar answered Jan 31 '23 05:01

gmh04


You are getting the coordinates from web browser's GeoLocation API.

like image 34
coderslay Avatar answered Jan 31 '23 06:01

coderslay