Results 1 to 6 of 6

Thread: HTML5 Geoloaction

  1. #1
    Join Date
    Mar 2010
    Location
    Canada
    Posts
    32
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default 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
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    The other person would need to choose to use your code (e.g., by using your website), which could then report their location to your server, and you could check it from there.

    Note that there are serious privacy considerations that you need to take into account: you need to make clear to the other person(s) that your site wishes to track their location (and *not* track them until they explicitly give their consent).
    Last edited by traq; 10-29-2012 at 08:35 PM.

  3. #3
    Join Date
    Mar 2010
    Location
    Canada
    Posts
    32
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    My final product would be to have a phone app that can track someone's location.
    There are millions people out there, how do I track person X with my phone.
    Does that person or I need to have a Google API key or something so we can be in sync with each other??

  4. #4
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Read the first sentence of my last post again.

  5. #5
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    I'm very confused about your questions here; why is this "HTML5"? Geolocation as far as I know is something done on the server (based on the IP address). One option is through Google. But there are other services as well. Are you specifically interested in Google Maps? If so, you should look into that specifically-- there are likely tutorials out there, and maybe a support forum.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  6. #6
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    the geolocation API for javascript is actually its own spec, but is often grouped with html5. It can be based on IP address, but uses finer locating via wifi network/cell tower triangulation and GPS whenever available. It's mostly useful with mobile devices.

    locbtran, geoloaction itself has nothing to do with google maps. It's all done on the user's device, which (if the user so chooses) shares that information with your app. If you want to know where someone is (more accurately, where their device is), you'd have to send that information to your server. At that point, you could access the info from wherever you happen to be. Then, if you wanted to, you could use that info to place a marker on google maps.

    some things you might want to read:

    dive into html5
    html5 doctor

Similar Threads

  1. UTF-8 with HTML5
    By techno_race in forum Coding tips & tutorials threads
    Replies: 16
    Last Post: 06-23-2012, 06:03 PM
  2. HTML5 Notepad script
    By ready4data in forum Dynamic Drive scripts help
    Replies: 3
    Last Post: 06-20-2012, 01:57 PM
  3. Resolved HTML5 tags and CSS
    By CChawps in forum HTML
    Replies: 6
    Last Post: 07-26-2011, 08:04 PM
  4. HTML5 help
    By john123a in forum HTML
    Replies: 3
    Last Post: 06-30-2011, 12:42 AM
  5. html5 video
    By ggalan in forum HTML
    Replies: 9
    Last Post: 06-03-2010, 07:57 PM

Bookmarks

Posting Permissions

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