Google Maps

The Google Maps API provides these web services as an interface for requesting Maps API data from external services and using them within your Maps applications. These services are designed to be used in conjunction with a map, as per the Maps API Terms of Service License Restrictions. To access map services you need to grab an access token by authenticating first. The analytics scope when generating a URL can be passed by simply setting 'maps' to getLoginURL(). Figure 1 shows how we can obtain an access token for Google Maps.

Figure 1. Authentication

$auth = eden('google')->auth('[CLIENT_ID]', '[CLIENT_SECRET]', '', '[API_KEY]');

//if no code and no session
if(!isset($_GET['code']) && !isset($_SESSION['token'])) {
    //redirect to login
    $login = $auth->getLoginUrl('maps');
    header('Location: '.$login);

//Code is returned back from google
if(isset($_GET['code'])) {
    //save it to session
	$access = $auth->getAccess($_GET['code']);
    $_SESSION['token'] = $access['access_token'];

When we have our token we can then access the different service levels of Google Maps.

Figure 2. Instantiate Maps
$maps = eden('google')->maps($_SESSION['token']);
Figure 3. Map Methods
Method Arguments Returns Description
$maps->direction(); none Eden_Google_Maps_Direction Returns Google maps direction
$maps->distance(); none Eden_Google_Maps_Distance Returns Google maps distance
$maps->elevation(); none Eden_Google_Maps_Elevation Returns Google maps elevation
$maps->geocoding(); none Eden_Google_Maps_Geocoding Returns Google maps geocoding
$maps->image(); none Eden_Google_Maps_Image Returns Google maps image

© 2012 Openovate Labs. All rights reserved.