Created
February 26, 2011 23:53
-
-
Save pbrisbin/845751 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // using the "Vehicle" API | |
| // a vehicle can be created from an arbitrary position / heading if you like | |
| position = { | |
| coords: { | |
| longitude: -71.00000 | |
| latitude: 42.00000 | |
| heading: 78 | |
| } | |
| } | |
| var v = new Vehicle(position); | |
| // you can init the vehicle from the current postion as returned | |
| // by geolocation, but you have to put all of your logic in the | |
| // callback | |
| initVehicleFromGeoLocation(function(vehicle) { | |
| // do what you want with 'vehicle' here | |
| }, | |
| function(msg) { /* i'm called on error */ }, | |
| function() { /* i'm called if geolocation is not supported */ } | |
| ); | |
| // once you have a vehicle you can view it's properties | |
| vehicle.latitude | |
| vehicle.longitude | |
| vehicle.heading.heading // 87 degrees | |
| vehicle.heading.direction // enum value for East (3) | |
| vehicle.heading.toString(); // shows "E" for east | |
| vehicle.toString(); // shows "vehicle: { latitude ... " | |
| // there are a few helpers too | |
| vehicle.sideOfVehicle(position) /* will tell you if the passed position | |
| is on the Left or Right of your vehicle */ | |
| vehicle.sideOfEvens(function(side) { | |
| // Left is 0 and Right is 1, so | |
| alert("even numbered addresses are on the " + (side ? "right" : "left")); | |
| }); /* for street cleaning queries */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment