Google Maps API for Business – REST URL signing

If you are a Google Maps API Business user, you have to sign REST URLs for invoking webservices. Here you can find an example how to do it in PHP:

function base64_encodesafe($plainText) {
  $base64 = base64_encode($plainText);
  return strtr($base64, '+/', '-_');
}

function base64_decodesafe($base64) {
  $base64 = strtr($base64, '-_', '+/');
  return base64_decode($base64);
}

$key = base64_decodesafe(GMAPS_KEY);
$url = "/maps/api/geocode/json?address=" . $address . "&client=" . GMAPS_CLIENT;
$signature = base64_encodesafe(hash_hmac("sha1", $url, $key, true));
$url = "http://maps.googleapis.com" . $url . "&signature=" . $signature;
Zveřejněno 11.4.2012 v 13:45 v rubrice PHP · Trvalý odkaz

Přidat komentář