jinjie

GoThere.SG API Experiment

Nov 8th, 2012
3,478
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.83 KB | None | 0 0
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2.  
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5.     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  6.     <title>GoThere.SG API Test</title>
  7.     <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
  8.     <script type="text/javascript" src="http://gothere.sg/jsapi?sensor=false"></script>
  9. </head>
  10. <body>
  11.  
  12. <div id="container">
  13.     <form>
  14.         <input type="text" name="address" id="address" value="658071" />
  15.         <input type="submit" name="button" value="Find" />
  16.     </form>
  17.    
  18.     <textarea style="width: 100%; height: 500px;"></textarea>
  19. </div>
  20.  
  21. </body>
  22. </html>
  23.  
  24.  
  25. <script language="javascript" type="text/javascript">
  26. <!--
  27. $(document).ready(function() {
  28.     $("form").submit(function() {
  29.         var address = $("#address").val();
  30.        
  31.         $.ajax({
  32.             url:        'http://gothere.sg/maps/geo',
  33.             dataType:   'jsonp',
  34.             data:       {
  35.                 'output'    : 'json',
  36.                 'q'         : address,
  37.                 'client'    : '',
  38.                 'sensor'    : false
  39.             },
  40.             type:   'GET',
  41.             success: function(data) {
  42.                 var field = $("textarea");
  43.                 var myString = "";
  44.                
  45.                 var status = data.Status;
  46.                 myString += "Status.code: " + status.code + "\n";
  47.                 myString += "Status.request: " + status.request + "\n";
  48.                 myString += "Status.name: " + status.name + "\n";
  49.                
  50.                 if (status.code == 200) {                  
  51.                     for (var i = 0; i < data.Placemark.length; i++) {
  52.                         var placemark = data.Placemark[i];
  53.                         var status = data.Status[i];
  54.                        
  55.                         myString += "============================\n";
  56.                         myString += "Placemark.id: " + placemark.id + "\n";
  57.                         myString += "Placemark.address: " + placemark.address + "\n";
  58.                         myString += "Placemark.AddressDetails.Country.CountryName: " + placemark.AddressDetails.Country.CountryName + "\n";
  59.                         myString += "Placemark.AddressDetails.Country.AddressLine: " + placemark.AddressDetails.Country.AddressLine + "\n";
  60.                         myString += "Placemark.AddressDetails.Country.Thoroughfare.ThoroughfareName: " + placemark.AddressDetails.Country.Thoroughfare.ThoroughfareName + "\n";
  61.                         myString += "Placemark.AddressDetails.Country.CountryNameCode: " + placemark.AddressDetails.Country.CountryNameCode + "\n";
  62.                         myString += "Placemark.AddressDetails.Accuracy: " + placemark.AddressDetails.Accuracy + "\n";
  63.                         myString += "Placemark.Point.coordinates: [" + placemark.Point.coordinates[0] + ", " + placemark.Point.coordinates[1] + ", " + placemark.Point.coordinates[2] + "]\n";
  64.                         myString += "============================\n";
  65.                     }
  66.                    
  67.                     field.val(myString);
  68.                 } else if (status.code == 603) {
  69.                     field.val("No Record Found");
  70.                 }
  71.  
  72.             },
  73.             statusCode: {
  74.                 404: function() {
  75.                     alert('Page not found');
  76.                 }
  77.             },
  78.         });
  79.        
  80.         return false;
  81.     });
  82. });
  83. // -->
  84. </script>
Advertisement
Add Comment
Please, Sign In to add comment