Last active
          May 9, 2016 23:41 
        
      - 
      
 - 
        
Save etoxin/40eb9ca3d49c2663ab8d to your computer and use it in GitHub Desktop.  
    Geolocation example
  
        
  
    
      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
    
  
  
    
  | <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <title>Boom!</title> | |
| <link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet"> | |
| <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script> | |
| <script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script> | |
| <script> | |
| var stuff = { | |
| run: function () { | |
| $('button').bind('click', function () { | |
| if ('geolocation' in navigator) { | |
| var geo_options = { | |
| enableHighAccuracy: true, | |
| maximumAge : 30000, | |
| timeout : 27000 | |
| }; | |
| navigator.geolocation.getCurrentPosition(stuff.send, stuff.error, geo_options); | |
| } | |
| }); | |
| }, | |
| error: function (msg) { | |
| console.log(msg); | |
| }, | |
| send: function (object) { | |
| $.ajax({ | |
| url: "https://api.mongolab.com/api/1/databases/geolocation/collections/boom?apiKey=XXXXXXXXXXXXXXXXXXXXXXXXXXXX", | |
| type: "POST", | |
| data: JSON.stringify( object ), | |
| contentType: "application/json" | |
| }).done(function( msg ) { | |
| console.log(msg); | |
| }); | |
| } | |
| }; | |
| $(function() { | |
| stuff.run(); | |
| }); | |
| </script> | |
| </head> | |
| <body> | |
| <div class="container"> | |
| <h1>Stuff.</h1> | |
| <p> | |
| <button class="btn btn-large">Press Me!</button> | |
| </p> | |
| </div> | |
| </body> | |
| </html> | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment