Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: Mobile GPS

  1. #1
    Regular Coder
    Join Date
    Oct 2009
    Posts
    434
    Thanks
    7
    Thanked 3 Times in 3 Posts

    Mobile GPS

    I am trying to get a fix on mobile devices, of course if they agree to their location to be given out.

    Just like some websites ask if my pc's location can be given out. But when I allow my pc's location it always shows a location in London, being my ISP, which must mean that the location is got using my IP address.

    Can anyone suggest how I can go about getting the exact or near exact location of mobile devices that connect to my site. Would it be using PHP and HTML or Javascript ? I have no idea where to start.

  • #2
    Regular Coder patryk's Avatar
    Join Date
    Oct 2012
    Location
    /dev/couch
    Posts
    398
    Thanks
    2
    Thanked 64 Times in 64 Posts
    javascript.
    check out this doc: http://dev.w3.org/geo/api/spec-source.html
    and here's nice demo with sources on github: http://html5demos.com/geo

    location is accessed via javascript obviusly. and then you do whatever you want with it

    basically it's
    Code:
    <script language="javascript">
    function successCallback(data){
    	document.writeln('accuracy: ' + data.coords.accuracy + '<br />');
    	document.writeln('altitude: ' + data.coords.altitude + '<br />');
    	document.writeln('altitude accuracy: ' + data.coords.altitudeAccuracy + '<br />');
    	document.writeln('heading: ' + data.coords.heading + '<br />');
    	document.writeln('latitude: ' + data.coords.latitude + '<br />');
    	document.writeln('longitude: ' + data.coords.longitude + '<br />');
    	document.writeln('speed: ' + data.coords.speed + '<br />');
    	document.writeln('timestamp: ' + data.timestamp);
    }
    
    function errorCallback(data){
    	document.writeln('error');
    }
    
    if(navigator.geolocation){
    	navigator.geolocation.getCurrentPosition(successCallback, errorCallback);
    }else{
    	document.writeln('not supported');
    }
    </script>
    yes it's that simple. paste it INSIDE document's body and open
    Last edited by patryk; 03-20-2013 at 02:08 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •