Skip to content

Chris' Laboratory

chrislee.kr – Personal blog as bookshelves

Menu
  • Home
  • Github
  • Contact Me
Menu

PTV Timetable API sample code for PHP

Posted on 11/10/201611/10/2016 by Chris Lee
Read Time:1 Minute, 20 Second

API Page: https://www.ptv.vic.gov.au/about-ptv/ptv-data-and-reports/digital-products/ptv-timetable-api/ptv-timetable-api-reference/

 

1. Request API key by sending email

How to register for a key and developer ID
> Send an email to APIKeyRequest@ptv.vic.gov.au with the following information in the subject line of the email:
• “PTV Timetable API – request for key”
> Once we’ve got your email request, we’ll send you a key and a developer ID by return email.

2. Run sample code

<?php 
	$userID = "<userID as developer ID>";
	$apiKey = "<API Key>";

	$requestURLHost = "http://timetableapi.ptv.vic.gov.au";
	$requestURL = "/v2/nearme/latitude/-37.82392124423254/longitude/144.9462017431463?devid=".$userID;
	$signature = hash_hmac("sha1", $requestURL, $apiKey);

	echo "signature => ".$signature.PHP_EOL;

	$finalURL = $requestURLHost.$requestURL."&signature=".$signature;
	echo "finalURL => ".$finalURL.PHP_EOL;

	$ch = curl_init(); 
	curl_setopt($ch, CURLOPT_URL, $finalURL); 
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
	$response = curl_exec ($ch); 
	curl_close ($ch); 

	echo "response => ".$response;

Response

 

$ php PTVTimetableAPI.php                                                                                                 
signature => XXXXXXXXXXX                                                          
finalURL => http://timetableapi.ptv.vic.gov.au/v2/nearme/latitude/-37.82392124423254/longitude/144.946201743146
3?devid=XXXXXXXX&signature=XXXXXXXXXXXX                                             
response => [                                                                                                  
  {                                                                                                            
    "result": {                                                                                                
      "distance": 158.73349,                                                                                   
      "suburb": "Southbank",                                                                                   
      "transport_type": "bus",                                                                                 
      "route_type": 2,                                                                                         
      "stop_id": 21722,                                                                                        
      "location_name": "West Gate Fwy/Lorimer St ",                                                            
      "lat": -37.82509,                                                                                        
      "lon": 144.94516                                                                                         
    },                                                                                                         
    "type": "stop"                                                                                             
  },                                                                                                           
  {                                                                                                            
    "result": {                                                                                                
      "distance": 274.8378,                                                                                    
      "suburb": "Docklands",                                                                                   
      "transport_type": "tram",                                                                                
      "route_type": 1,                                                                                         
      "stop_id": 2490,                                                                                         
      "location_name": "D17-Merchant St/Collins St ",                                                          
      "lat": -37.82153,                                                                                        
      "lon": 144.945419                                                                                        
    },                                                                                                         
    "type": "stop"                                                                                             
  },                                                                                                           
  .....
]

 

Share

Facebook
Twitter
LinkedIn
Email

Related

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Categories

  • Databases (11)
    • MongoDB (4)
    • MS-SQL (1)
    • MySQL (6)
  • E-Commerce (8)
    • Magento (8)
  • Finance (2)
  • Frameworks (84)
    • Adobe Flex (1)
    • Angular (ngx) (3)
    • Codeigniter (6)
    • CSS (5)
    • Django (2)
    • Javascript (13)
    • Node.js (6)
    • PHP (17)
    • React Native (4)
    • React.js (1)
    • Sencha Touch (4)
    • Terraform (1)
    • Vue.js (1)
    • WordPress (4)
    • Yii2 (3)
  • General Documents (15)
  • Marketing (3)
  • Mobile Development (33)
    • Android (20)
    • iPhone (13)
  • Platforms (21)
    • Arduino (2)
    • Docker (5)
    • Google App Engine (5)
    • Raspberry Pi (5)
    • Samsung Smart TV (4)
  • Security (17)
  • Server (31)
    • Linux (13)
  • Tools (14)
    • SVN (7)
  • Uncategorized (3)

Search

Recent Posts

  • helm list error stream ID 3; INTERNAL_ERROR
  • Bootstrapping Kubernetes cluster with kubeadm
  • Taint all resources in the one module
  • Alpine – Plugin caching_sha2_password could not be loaded
  • npm link with peerDependencies

Recent Comments

  • Obayed on Binance Auto Trading Bot – Buy low/Sell high with stop loss limit/Trade multiple coins
  • Ari on How to install memcache.so/memcached.so for MAMP Pro (Mac)
  • Mida ali on Binance Auto Trading Bot – Buy low/Sell high with stop loss limit/Trade multiple coins
  • Chris Lee on How to install memcache.so/memcached.so for MAMP Pro (Mac)
  • Chris Lee on Setting Up A VPN Server On OSX 10.6

Tags

1 ajax amazon android android-addpart browser chrislee-kr codeigniter codeigniter-tcpdf com-apple-net-racoon CSS CSS history hack delpaigmail-com entity-addpart-double exception-printing-is-disabled-by-default-for-security-reasons ext-plugins-listpagingplugin ext-plugins-listpagingplugin-example f iphone javascript jquery-defaultchecked jquery-samsung-smart-tv listpagingplugin mac magento-exception-printing-is-disabled-by-default-for-security-reasons magento-sample-data-exception-printing-is-disabled-by-default-for-security-reasons nu-vot null-core-errors-confignotfound-config-mk9engine-ini php samsung-smart-tv-jquery samsung-smart-tv-sdk-ajax samsung-smart-tv-sdk-jquery samsung-tv-sdk samsung-tv-sdk-jquery samsung tv sencha-smart-tv sencha-touch-list-paging smart-tv-jquery sqlite subversion svn tcedook tcpdf-codeigniter uilinebreakmodecharacterwrap-is-deprecated unknown-column-link-area

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
© 2023 Chris' Laboratory | Powered by Minimalist Blog WordPress Theme