#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2010
    Posts
    46
    Rep Power
    5

    HTML5 Geoloaction


    HTML5 GeoLocation

    I know there's an app for this but I would like to learn how to do this.
    When I upload my code onto the server it can find where I am in realtime with geolocatin.
    But if I would like to monitor someone using the geolocation, how would I go about doing ths??
    Do you need to download a Google API or something??

    So if I am currently at location A and personXY is at location B. If I was to look at my monitor, how do I see personXY on google map in realtime.
    Any tips or advice would be greatly appreciated.


    Here's my code, that only monitors myself
    Code:
    <!DOCTYPE html>
    <HTML>
    <HEAD>
    <TITLE></TITLE>
    <script src="http://maps.google.com/maps/api/js?sensor=false"></script>
    
    <script type="text/javascript">
       var TIMEOUT = 300000;         
       var MAX_AGE = 1000;           
       var HIGH_ACC = true;          
       var ZOOM = 10;
    
       var watchID; 
       var map;                      
       var mapMarker;                
    
       
       window.onload = function (){
          if (navigator.geolocation) {
             watchID = navigator.geolocation.watchPosition(show_map, errorCheck, {
             maximumAge: MAX_AGE,
             timeout: TIMEOUT,
             enableHighAccuracy: HIGH_ACC 
          });
          }else {
             alert("Oops, Geolocation Not Supported.");
          }
       }
       
       
       function stopWatch(){
          if (watchID) {
             navigator.geolocation.clearWatch (watchID);
          }
             watchID = null;
       }   
        
        
       function errorCheck(error){      
          switch(error.code){
             case error.TIMEOUT:
                alert("Geolocation Timeout");
                break;
             case error.POSITION_UNAVAILABLE:
                alert("Geolocation Position Unavailable");
                break;
             case error.PERMISSION_DENIED:
                alert("Geolocation Permission Denied");
                break;
             default:
                alert("Geolocation Error Code: " + error.code);
          }
       }
       
       
       function show_map(position) {
          var lat = position.coords.latitude;
          var lon = position.coords.longitude;
          
          var latlng = new google.maps.LatLng(lat, lon);
    
          if(map) {                           
             map.panTo(latlng);
             mapMarker.setPosition(latlng);
          } else {                            
             var myOptions = {
                zoom: ZOOM,
                center: latlng,
                mapTypeId: google.maps.MapTypeId.ROADMAP
             };
             map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    
             mapMarker = new google.maps.Marker({
                position: latlng,
                title:"You are here.",
                clickable: true
             });
             mapMarker.setMap(map);
          }
    
       }   
    </script>
    </HEAD>
    <BODY>
     
    <div id="map_canvas"></div>
    
    </BODY>
    </HTML>
  2. #2
  3. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,317
    Rep Power
    7170
    But if I would like to monitor someone using the geolocation, how would I go about doing ths??
    You would need to modify the script to automatically send the visitor's location back to the server at a regular interval. The server can then store the location in a database. Then on the viewing side, you would need to periodically retrieve that location back from the server and plot it.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2010
    Posts
    46
    Rep Power
    5
    Originally Posted by E-Oreo
    You would need to modify the script to automatically send the visitor's location back to the server at a regular interval. The server can then store the location in a database. Then on the viewing side, you would need to periodically retrieve that location back from the server and plot it.
    I understand how to store the location and plot it onto a graph but how do I get the location from that person. I mean, there are millions of people out there but how do I get the location of person X? Do they or I need to download a Google API or something so I can track them.

    My final product is to have app for the android or iphone that can track a certain person on my cell phone.
  6. #4
  7. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,317
    Rep Power
    7170
    They would have to download your app and be actively running it in order for you to get the location.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around

IMN logo majestic logo threadwatch logo seochat tools logo