PHP code example of arraypress / google-maps-static
1. Go to this page and download the library: Download arraypress/google-maps-static library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
arraypress / google-maps-static example snippets
use ArrayPress\Google\MapsStatic\Client;
// Initialize client with your API key
$client = new Client( 'your-google-api-key' );
// Configure options using method chaining
$client
->set_size( 800, 600 )
->set_zoom( 15 )
->set_map_type( 'roadmap' )
->set_format( 'png' )
->set_scale( 2 )
->set_language( 'en' )
->set_region( 'US' );
// Generate a basic map for a location
$map_url = $client->location( 'Seattle, WA' );
$img_tag = $client->generate_image_tag( $map_url );
// Create a map with markers
$markers = [
[
'style' => [ 'color' => 'red', 'label' => 'A' ],
'locations' => [ 'Seattle, WA' ]
]
];
$map_url = $client->markers( $markers );
// Generate a map with a custom path
$path_points = [ 'Seattle, WA', 'Portland, OR' ];
$map_url = $client->path( $path_points );
// Map dimensions and display
$client->set_size( 800, 600 ); // Set width and height
$client->set_zoom( 15 ); // Set zoom level (0-21)
$client->set_map_type( 'satellite' ); // roadmap, satellite, terrain, hybrid
$client->set_format( 'png' ); // png, jpg, gif
$client->set_scale( 2 ); // 1, 2, or 4
// Localization
$client->set_language( 'en' ); // Language code
$client->set_region( 'US' ); // Region code
// Street view settings
$client->set_heading( 90 ); // 0-360 degrees
$client->set_pitch( - 30 ); // -90 to 90 degrees
// API management
$client->set_api_key( 'new-key' ); // Update API key
$client->reset_options(); // Reset to defaults
// Map configuration
$dimensions = $client->get_size(); // Returns ['width' => int, 'height' => int]
$zoom = $client->get_zoom(); // Current zoom level
$type = $client->get_map_type(); // Current map type
$format = $client->get_format(); // Current image format
$scale = $client->get_scale(); // Current scale factor
// Localization settings
$language = $client->get_language(); // Current language code
$region = $client->get_region(); // Current region code
// Street view settings
$heading = $client->get_heading(); // Current heading in degrees
$pitch = $client->get_pitch(); // Current pitch in degrees
// API and options
$key = $client->get_api_key(); // Current API key
$options = $client->get_options(); // All current options