Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
John Bergandino
8,455 PointsWhich Code is best for GPS Tracking and User Input?
I'm looking to build an application that can track 20 trucks via GPS (200 mile radius) and allow the truck drivers to input their arrival times, departure times, etc and have all that data accessible on 1 website. I also want to have the arrival/departure times transmit into our desktop software via automatic EDI transmissions. My ultimate goal is to write a program that will tell me the best truck to dispatch based on all the current truck locations (among other variables).
What is the best language to focus on for this type of programming? It seems like database focused code is mentioned often upon researching GPS applications but I'm not really sure where to start. Thank you.
1 Answer
Jordan Hauge
6,095 PointsI just built a very simple application that finds restaurants around you and displays one at random along with reviews, an image, and the distance from your location. It grabs data from google maps API for geolocation along with some HTML5 and JavaScript. The whole app is built with JavaScript, and it queries Yelp and Googles API's with AJAX and Jquery.
Below is an example of how I grabbed the users location using JavaScript.
///////// GEOLOCATION //////////
// Ensure the browser is geolocation enabled
if('geolocation' in navigator){
console.log("Geolocation is supported!");
}else{
console.log("This browser is not geolocation enabled.");
}
var options = {
// enableHighAccuracy = true: more accurate result, false: less accurate
enableHighAccuracy: false,
// timeout = how long does the device have, (milliseconds) to return a result?
timeout: 5000,
// maximumAge = max age for a possible cached position. 0 = returns current position
maximumAge: 0
};
// call getCurrentPosition()
navigator.geolocation.getCurrentPosition(success, error, options);
// upon success, do this
function success(pos){
// get longitude and latitude from the position object passed in
lng = pos.coords.longitude;
lat = pos.coords.latitude;
// Log location coordinates to the console
console.log(lng + " " + lat); // <-- Will display your current longitude and latitude on the console
// ALL DATA THAT HAS TO DO WITH LOCATION MUST BE ENTERED WITHIN THE SUCCESS BRACKETS
};