staticmap.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /*
  3. Copyright (c) 2009-2014 F3::Factory/Bong Cosca, All rights reserved.
  4. This file is part of the Fat-Free Framework (http://fatfree.sf.net).
  5. THE SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF
  6. ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  7. IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  8. PURPOSE.
  9. Please see the license.txt file for more information.
  10. */
  11. namespace Web\Google;
  12. //! Google Static Maps API v2 plug-in
  13. class StaticMap {
  14. const
  15. //! API URL
  16. URL_Static='http://maps.googleapis.com/maps/api/staticmap';
  17. protected
  18. //! Query arguments
  19. $query=array();
  20. /**
  21. * Specify API key-value pair via magic call
  22. * @return object
  23. * @param $func string
  24. * @param $args array
  25. **/
  26. function __call($func,array $args) {
  27. $this->query[]=array($func,$args[0]);
  28. return $this;
  29. }
  30. /**
  31. * Generate map
  32. * @return string
  33. **/
  34. function dump() {
  35. $fw=\Base::instance();
  36. $web=\Web::instance();
  37. $out='';
  38. return ($req=$web->request(
  39. self::URL_Static.'?'.array_reduce(
  40. $this->query,
  41. function($out,$item) {
  42. return ($out.=($out?'&':'').
  43. urlencode($item[0]).'='.urlencode($item[1]));
  44. }
  45. ))) && $req['body']?$req['body']:FALSE;
  46. }
  47. }