public function render(
        $language = 'en',
        array $libraries = array(),
        $callback = null,
        $api_key = null
    )
    {
        $otherParameters = array();

        if (!empty($libraries)) {
            $otherParameters['libraries'] = implode(',', $libraries);
        }

        $otherParameters['language'] = $language;

        // Google Maps API warning: NoApiKeys https://developers.google.com/maps/documentation/javascript/error-messages#no-api-keys
        if (!is_null($api_key)) {
            $otherParameters['key'] = $api_key;
        }

        $this->jsonBuilder
            ->reset()
            ->setValue('[other_params]', urldecode(http_build_query($otherParameters)));

        if ($callback !== null) {
            $this->jsonBuilder->setValue('[callback]', $callback, false);
        }

        $callbackFunction = 'load_ivory_google_map_api';
        $url = sprintf('//www.google.com/jsapi?callback=%s', $callbackFunction);
        $loader = sprintf('google.load("maps", "3", %s);', $this->jsonBuilder->build());

        $output = array();
        $output[] = '<script type="text/javascript">'.PHP_EOL;
        $output[] = sprintf('function %s () { %s };'.PHP_EOL, $callbackFunction, $loader);
        $output[] = '</script>'.PHP_EOL;
        $output[] = sprintf('<script type="text/javascript" src="%s"></script>'.PHP_EOL, $url);

        $this->loaded = true;

        return implode('', $output);
    }
public function render(
        $language = 'en',
        array $libraries = array(),
        $callback = null,
        $api_key = null
    )
    {
        $otherParameters = array();

        if (!empty($libraries)) {
            $otherParameters['libraries'] = implode(',', $libraries);
        }

        $otherParameters['language'] = $language;

        // Google Maps API warning: NoApiKeys https://developers.google.com/maps/documentation/javascript/error-messages#no-api-keys
        if (!is_null($api_key)) {
            $otherParameters['key'] = $api_key;
        }

        $this->jsonBuilder
            ->reset()
            ->setValue('[other_params]', urldecode(http_build_query($otherParameters)));

        if ($callback !== null) {
            $this->jsonBuilder->setValue('[callback]', $callback, false);
        }

        $callbackFunction = 'load_ivory_google_map_api';
        $url = sprintf('//www.google.com/jsapi?callback=%s', $callbackFunction);
        $loader = sprintf('google.load("maps", "3", %s);', $this->jsonBuilder->build());

        $output = array();
        $output[] = '<script type="text/javascript">'.PHP_EOL;
        $output[] = sprintf('function %s () { %s };'.PHP_EOL, $callbackFunction, $loader);
        $output[] = '</script>'.PHP_EOL;
        $output[] = sprintf('<script type="text/javascript" src="%s"></script>'.PHP_EOL, $url);

        $this->loaded = true;

        return implode('', $output);
    }
public function render ( $ language = 'en' , array $ libraries = array ( ) , $ callback = null , $ api_key = null ) { $ otherParameters = array ( ) ; if ( ! empty ( $ libraries ) ) { $ otherParameters [ 'libraries' ] = implode ( ',' , $ libraries ) ; } $ otherParameters [ 'language' ] = $ language ; // Google Maps API warning: NoApiKeys https://developers.google.com/maps/documentation/javascript/error-messages#no-api-keys if ( ! is_null ( $ api_key ) ) { $ otherParameters [ 'key' ] = $ api_key ; } $ this -> jsonBuilder -> reset ( ) -> setValue ( '[other_params]' , urldecode ( http_build_query ( $ otherParameters ) ) ) ; if ( $ callback !== null ) { $ this -> jsonBuilder -> setValue ( '[callback]' , $ callback , false ) ; } $ callbackFunction = 'load_ivory_google_map_api' ; $ url = sprintf ( '//www.google.com/jsapi?callback=%s' , $ callbackFunction ) ; $ loader = sprintf ( 'google.load("maps", "3", %s);' , $ this -> jsonBuilder -> build ( ) ) ; $ output = array ( ) ; $ output [ ] = '<script type="text/javascript">' . PHP_EOL ; $ output [ ] = sprintf ( 'function %s () { %s };' . PHP_EOL , $ callbackFunction , $ loader ) ; $ output [ ] = '</script>' . PHP_EOL ; $ output [ ] = sprintf ( '<script type="text/javascript" src="%s"></script>' . PHP_EOL , $ url ) ; $ this -> loaded = true ; return implode ( '' , $ output ) ; }
Renders the API.

@param string  $language  The language.
@param array   $libraries Additionnal libraries.
@param string  $callback  A JS callback.
@param string  $api_key   Google Browser API key for the map

@return string The HTML output.
Renders the API .