Skip to main content

Real time GPS Tracker on JUST HTML / JS and Google Maps to be run on a mobile phone

Most browsers in the latest smart phones have implemented the W3C Geo location:
The Geolocation API defines a high-level interface to location information associated only with the device hosting the implementation, such as latitude and longitude. The API itself is agnostic of the underlying location information sources. 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, as well as user input. No guarantee is given that the API returns the device's actual location.
The API is designed to enable both "one-shot" position requests and repeated position updates, as well as the ability to explicitly query the cached positions.

Using the Geolocation API to plot a point on Google Maps, will look something like this:

   
if (navigator.geolocation) { 
  navigator.geolocation.getCurrentPosition(function(position) {  

    var point = new google.maps.LatLng(position.coords.latitude, 
                                       position.coords.longitude);

    // Initialize the Google Maps API v3
    var map = new google.maps.Map(document.getElementById('map'), {
       zoom: 15,
      center: point,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    });

    // Place a marker
    new google.maps.Marker({
      position: point,
      map: map
    });
  }); 
} 
else {
  alert('W3C Geolocation API is not available');
} 
 
 The above will only gather the position once, and will not auto update 
when you start moving. To handle that, you would need to keep a 
reference to your marker, periodically call the getCurrentPosition() method,
 and move the marker to the new coordinates. The code might look something 
like this:
 // Initialize the Google Maps API v3
var map = new google.maps.Map(document.getElementById('map'), {
  zoom: 15,
  mapTypeId: google.maps.MapTypeId.ROADMAP
});

var marker = null;

function autoUpdate() {
  navigator.geolocation.getCurrentPosition(function(position) {  
    var newPoint = new google.maps.LatLng(position.coords.latitude, 
                                          position.coords.longitude);

    if (marker) {
      // Marker already created - Move it
      marker.setPosition(newPoint);
    }
    else {
      // Marker does not exist - Create it
      marker = new google.maps.Marker({
        position: newPoint,
        map: map
      });
    }

    // Center the map on the new position
    map.setCenter(newPoint);
  }); 

  // Call the autoUpdate() function every 5 seconds
  setTimeout(autoUpdate, 5000);
}

autoUpdate();
 
Now if by tracking you mean that you should also store this information 
on a server (so that someone else could see you moving from a remote 
location), then you'd have to send the points to a server-side script 
using AJAX. 
 

Comments

Unknown said…
complete good information provide your blog rfid gps tracking

Your blog is really very interesting information regarding real estate.

Bhartiya City Nikoo Homes
Mantri Serenity
Anonymous said…
Nice blog..! I really loved reading through this article. Thanks for sharing such an amazing post with us and keep blogging...Well written article Thank You for Sharing with Us | project management training in chennai | project management certification online | project management course online |
ibtdubai said…
I like the topic which has been discuss by you,i want to say thanks to you for sharing informative info. Alternatively specially create a great blog for CompIT.

IT Support Services Dubai
Madhan kumar said…
Hey, Wow all the posts are very informative for the people who visit this site. Good work! We also have a Website. Please feel free to visit our site. Thank you for sharing.
Be Your Own Boss! If you're looking for a change in your work prospects, then let's prepare for your career from here!!!
Self Employment | Women Development | Information Technology | Engineering Courses

Popular posts from this blog

CCNA3 v4.0 Final Exam Answers Updated 2013 100%

1. Refer to the exhibit. A network administrator needs to add IP phones to the network. To which devices should the IP phones connect? AS1 and AS2 DS1 and DS2 DS1, DS2, and CS1 AS1, AS2, DS1, and DS2 2. Which CLI mode allows users to access all device commands, such as those used for configuration, management, and troubleshooting? user EXEC mode privileged EXEC mode global configuration mode interface configuration mode 3. Refer to the exhibit. Which Spanning Tree Protocol version is in effect? Per VLAN Spanning Tree (PVST) Per VLAN Spanning Tree + (PVST+) Common Spanning Tree (CST) Rapid Spanning Tree Protocol (RSTP) Multiple Spanning Tree Protocol (MSTP) 4. Refer to the exhibit. A network administrator has segmented the network into two VLANs and configured Router1 for inter-VLAN routing. A test of the network, however, shows that hosts on each VLAN can only access local resources and not resources on the other VLAN. What is the most likely cause of this pr

CCNA 2 EROUTING version 4 2013 FINAL EXAM ANSWERS 100%

CCNA 2 Final Exam 2013 v 4   1. Refer to the exhibit. A network engineer removes a new router from the shipping container and powers on the router to ensure it passes POST. Which port would the engineer use to perform the initial configuration? AUX console FE0/0 FE0/1 2. What is the purpose of the TTL field within an IP packet header? clears an unreachable route from the routing table after the invalid timer expires prevents regular update messages from inappropriately reinstating a route that may have gone bad removes an unreachable route from the routing table after the flush timer expires limits the period of time or number of hops a packet can traverse through the network before it should be discarded used to mark the route as unreachable in a routing update that is sent to other routers 3. When would the network administrator use the ip bandwidth-percent eigrp as-number percent command? when there is a low bandwidth connection when the connec

CCNA3 v3.0 Final Exam Answers Updated 2013 100%

1. Refer to the exhibit. The Layer 2 switching design that is shown has been implemented in a campus environment that is using Spanning Tree Protocol. All inter-switch links that are shown are trunks. Whenever an inter-switch link fails, the network takes nearly a minute to completely converge. How can the convergence time be reduced? Increase the capacity of the distribution and core trunk links to 10 Gb/s. Add a trunk link that directly connects D1 and D2. Use Layer 3 switching on the core switch. Implement Rapid Spanning Tree Protocol 2. Refer to the exhibit. R1 is configured for traditional inter-VLAN routing. R1 can ping computer 3 but cannot ping computer 1. What is a possible cause for this failure? S1 port Fa0/11 is in the wrong VLAN. R1 does not have an active routing protocol. The IP address of computer 1 is in the wrong logical network. Router interface Fa0/0 has the wrong trunk encapsulation type configured. 3. Refer to the exhibit. What will allow a h