arraypress / mapkit
A PHP library for generating map URLs for various services including Google Maps, Apple Maps, Bing Maps, OpenStreetMap, Waze, and Yandex Maps, with support for coordinates, directions, and search functionality.
Requires
- php: >=7.4
This package is auto-updated.
Last update: 2024-12-19 11:40:22 UTC
README
A comprehensive PHP library for generating URLs and embeds for various map services including Google Maps, Bing Maps, and Apple Maps. Provides a fluent interface for building map URLs with support for coordinates, search, directions, custom views, and more.
Features
- πΊοΈ Multi-Service Support: Generate URLs for Google Maps, Bing Maps, and Apple Maps
- π Location Handling: Coordinate-based locations and place searches
- π Direction Support: Complex routing with waypoints and travel modes
- π¨ View Customization: Multiple map types and layer options
- π Street View: Support for Google Street View and Bing Bird's Eye view
- π± Embed Generation: Create embeddable map iframes
- π Internationalization: Language and region preferences
- π¦ Traffic & Transit: Real-time traffic and public transportation overlays
- π Collections: Support for multiple location markers and points of interest
Requirements
- PHP 7.4 or later
- WordPress 6.7.1 or later
Installation
Install via Composer:
composer require arraypress/mapkit
Basic Usage
use ArrayPress\MapKit\Client; // Initialize client $mapkit = new Client(); // Generate URLs for all services at once $urls = $mapkit->get_all_urls( 40.7484, -73.9857, 15 ); // Empire State Building // Or use specific services $google_url = $mapkit->google() ->coordinates( 40.7484, -73.9857 ) ->zoom( 15 ) ->get_url(); $bing_url = $mapkit->bing() ->coordinates( 40.7484, -73.9857 ) ->zoom( 15 ) ->get_url(); $apple_url = $mapkit->apple() ->coordinates( 40.7484, -73.9857 ) ->zoom( 15 ) ->get_url();
Google Maps Features
Basic Maps
$google = $mapkit->google(); // Simple map view $url = $google->coordinates( 40.7484, -73.9857 ) ->zoom( 15 ) ->get_url(); // Satellite view $url = $google->coordinates( 40.7484, -73.9857) ->zoom( 18 ) ->basemap( 'satellite' ) ->get_url(); // Show traffic $url = $google->coordinates( 40.7484, -73.9857 ) ->layer( 'traffic' ) ->get_url();
Search
// Basic search $url = $google->search( 'Empire State Building' ) ->get_url(); // Search with Place ID $url = $google->search( 'Empire State Building', 'ChIJaXQRs6lZwokRY6EFpJnhNNE' ) ->get_url(); // Localized search $url = $google->search( 'Empire State Building' ) ->language( 'es' ) ->region( 'US' ) ->get_url();
Directions
// Basic directions $url = $google->from( 'Times Square' ) ->to( 'Empire State Building' ) ->get_url(); // Complex routing $url = $google->from( 'Times Square' ) ->to( 'Empire State Building' ) ->waypoints( [ 'Madison Square Garden'] ) ->travel_mode( 'walking' ) ->avoid( [ 'highways', 'tolls' ] ) ->get_url(); // Transit directions $url = $google->from( 'Grand Central' ) ->to( 'Central Park' ) ->travel_mode( 'transit' ) ->get_url();
Street View
// Basic Street View $url = $google->coordinates( 40.7484, -73.9857 ) ->street_view() ->get_url(); // Customized view $url = $google->coordinates( 40.7484, -73.9857 ) ->street_view( null, 180, 20, 90 ) // heading, pitch, FOV ->get_url();
Embedded Maps
// Basic embed $embed = $google->coordinates( 40.7484, -73.9857 ) ->zoom( 15 ) ->as_embed() ->get_embed(); // Custom size embed $embed = $google->coordinates( 40.7484, -73.9857 ) ->zoom( 15 ) ->as_embed( 800, 600 ) ->get_embed();
Bing Maps Features
Basic Maps
$bing = $mapkit->bing(); // Road view $url = $bing->coordinates( 40.7484, -73.9857 ) ->style( 'road' ) ->get_url(); // Aerial view $url = $bing->coordinates( 40.7484, -73.9857 ) ->style( 'satellite' ) ->get_url(); // Bird's eye view $url = $bing->coordinates( 40.7484, -73.9857 ) ->style( 'birds-eye' ) ->birds_eye( null, 180 ) ->get_url();
Search
// Location search $url = $bing->search( 'Empire State Building' ) ->get_url(); // Business search $url = $bing->business_search( 'restaurants near Times Square' ) ->get_url(); // Sorted business search $url = $bing->business_search( 'restaurants', 2 ) // Sort by rating ->get_url();
Directions
// Basic directions $url = $bing->from( 'Times Square' ) ->to( 'Empire State Building' ) ->get_url(); // Transit directions with timing $url = $bing->from( 'Grand Central' ) ->to( 'Central Park' ) ->travel_mode( 'transit' ) ->transit_time( 'depart', '202403151430' ) ->get_url(); // Route with traffic $url = $bing->from( 'Times Square' ) ->to( 'Empire State Building' ) ->route_options( false, true ) // Show traffic ->get_url();
Collections
// Single point $url = $bing->add_point( 40.7484, -73.9857, 'Empire State Building', 'Iconic NYC landmark' )->get_url(); // Multiple points $url = $bing->add_point( 40.7484, -73.9857, 'Empire State Building' ) ->add_point( 40.7580, -73.9855, 'Times Square' ) ->get_url();
Apple Maps Features
Basic Maps
$apple = $mapkit->apple(); // Standard view $url = $apple->coordinates( 40.7484, -73.9857 ) ->map_type( 'standard' ) ->get_url(); // Satellite view $url = $apple->coordinates( 40.7484, -73.9857 ) ->map_type( 'satellite' ) ->get_url(); // Hybrid view $url = $apple->coordinates( 40.7484, -73.9857 ) ->map_type( 'hybrid' ) ->get_url();
Search and Directions
// Search $url = $apple->search( 'Empire State Building' ) ->get_url(); // Directions $url = $apple->from( 'Times Square' ) ->to( 'Empire State Building' ) ->transport_type( 'walking' ) ->get_url();
Additional Features
// Add pin $url = $apple->coordinates( 40.7484, -73.9857 ) ->add_pin( 40.7484, -73.9857) ->get_url(); // Set locale $url = $apple->coordinates( 40.7484, -73.9857 ) ->language( 'es' ) ->region( 'US' ) ->get_url();
Advanced Usage
Method Chaining
All service builders support method chaining for a fluent interface:
$url = $mapkit->google() ->coordinates( 40.7484, -73.9857 ) ->zoom( 15 ) ->basemap( 'satellite' ) ->layer( 'traffic' ) ->language( 'en' ) ->region( 'US' ) ->get_url();
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
License
Licensed under the GPLv2 or later license.
Support
For more information and support: