staticmap.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /*
  3. Copyright (c) 2009-2019 F3::Factory/Bong Cosca, All rights reserved.
  4. This file is part of the Fat-Free Framework (http://fatfreeframework.com).
  5. This is free software: you can redistribute it and/or modify it under the
  6. terms of the GNU General Public License as published by the Free Software
  7. Foundation, either version 3 of the License, or later.
  8. Fat-Free Framework is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License along
  13. with Fat-Free Framework. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. namespace Web\Google;
  16. //! Google Static Maps API v2 plug-in
  17. class StaticMap {
  18. const
  19. //! API URL
  20. URL_Static='http://maps.googleapis.com/maps/api/staticmap';
  21. protected
  22. //! Query arguments
  23. $query=array();
  24. /**
  25. * Specify API key-value pair via magic call
  26. * @return object
  27. * @param $func string
  28. * @param $args array
  29. **/
  30. function __call($func,array $args) {
  31. $this->query[]=array($func,$args[0]);
  32. return $this;
  33. }
  34. /**
  35. * Generate map
  36. * @return string
  37. **/
  38. function dump() {
  39. $fw=\Base::instance();
  40. $web=\Web::instance();
  41. $out='';
  42. return ($req=$web->request(
  43. self::URL_Static.'?'.array_reduce(
  44. $this->query,
  45. function($out,$item) {
  46. return ($out.=($out?'&':'').
  47. urlencode($item[0]).'='.urlencode($item[1]));
  48. }
  49. ))) && $req['body']?$req['body']:FALSE;
  50. }
  51. }