Laravel Google Maps Package

Overview

Laravel Google Maps

Rank Total Downloads Latest Stable Version Latest Unstable Version License

This repo aims to use google map features in laravel 5.x. It is easy to use and flexible, you can just install this package and enjoy google map in your website and/or applications.

Features

1. Localizing
2. Map Types
3. Custom Style
4. Makers
5. Info Window
6. Shapes
7. Symbols
8. Overlays
9. KML and GeoRSS
10. Traffic and Bicycling Layer
11. Geocoding Caches
12. Controls
13. Street View
14. Events
15. Reverse Geocoding
16. Travel Moding
17. Proxy

Services & Libraries

1. Directions
2. Geocoding
3. Geometry
4. Drawing
5. Places
6. Autocomplete
7. Adsense
8. Geofence (For now only server side geofence available)

Installation

Add in composer.json

  "require": {
      "farhanwazir/laravelgooglemaps": "^2.3"
      ----
  }

Then

  composer update

Or install via composer cli

  composer require farhanwazir/laravelgooglemaps

Add service provider config/app.php

        FarhanWazir\GoogleMaps\GMapsServiceProvider::class,

And finally add in the alias section config/app.php

        'GMaps' => FarhanWazir\GoogleMaps\Facades\GMapsFacade::class,

Now publish configuration file

    php artisan vendor:publish --provider="FarhanWazir\GoogleMaps\GMapsServiceProvider"

##Usage Example files are under FarhanWazir/GoogleMaps/Example:

Controller Example; reference code for display method

/******** Custom Map Controls ********/

        $leftTopControls = ['document.getElementById("leftTopControl")']; // values must be html or javascript element
        $this->gmap->injectControlsInLeftTop = $leftTopControls; // inject into map
        $leftCenterControls = ['document.getElementById("leftCenterControl")'];
        $this->gmap->injectControlsInLeftCenter = $leftCenterControls;
        $leftBottomControls = ['document.getElementById("leftBottomControl")'];
        $this->gmap->injectControlsInLeftBottom = $leftBottomControls;

        $bottomLeftControls = ['document.getElementById("bottomLeftControl")'];
        $this->gmap->injectControlsInBottomLeft = $bottomLeftControls;
        $bottomCenterControls = ['document.getElementById("bottomCenterControl")'];
        $this->gmap->injectControlsInBottomCenter = $bottomCenterControls;
        $bottomRightControls = ['document.getElementById("bottomRightControl")'];
        $this->gmap->injectControlsInBottomRight = $bottomRightControls;

        $rightTopControls = ['document.getElementById("rightTopControl")'];
        $this->gmap->injectControlsInRightTop = $rightTopControls;
        $rightCenterControls = ['document.getElementById("rightCenterControl")'];
        $this->gmap->injectControlsInRightCenter = $rightCenterControls;
        $rightBottomControls = ['document.getElementById("rightBottomControl")'];
        $this->gmap->injectControlsInRightBottom = $rightBottomControls;

        $topLeftControls = ['document.getElementById("topLeftControl")'];
        $this->gmap->injectControlsInTopLeft = $topLeftControls;
        $topCenterControls = ['document.getElementById("topCenterControl")'];
        $this->gmap->injectControlsInTopCenter = $topCenterControls;
        $topRightControls = ['document.getElementById("topRightControl")'];
        $this->gmap->injectControlsInTopRight = $topRightControls;

        /******** End Controls ********/

        $config = array();
        $config['map_height'] = "100%";
        $config['center'] = 'Clifton, Karachi';
        
        $this->gmap->initialize($config); // Initialize Map with custom configuration

        /*********** Marker Setup ***********/
        $marker = array();
        $marker['draggable'] = true;
        //Marker event dragend
        $marker['ondragend'] = '
        iw_'. $this->gmap->map_name .'.close();
        reverseGeocode(event.latLng, function(status, result, mark){
            if(status == 200){
                iw_'. $this->gmap->map_name .'.setContent(result);
                iw_'. $this->gmap->map_name .'.open('. $this->gmap->map_name .', mark);
            }
        }, this);
        ';
        $this->gmap->add_marker($marker);
        /*********** End Marker Setup ***********/

        $map = $this->gmap->create_map(); // This object will render javascript files and map view; you can call JS by $map['js'] and map view by $map['html']

        return view('map', ['map' => $map]);

Route Example

Route::get('/map', 'MapController@index');

Route::get('/', function(){
    $config = array();
    $config['center'] = 'New York, USA';
    GMaps::initialize($config);
    $map = GMaps::create_map();

    echo $map['js'];
    echo $map['html'];
});

View Example

<html>
    <head>
        {!! $map['js'] !!}
    </head>
<body>
    <div class="container">
        <div class="content">
            <div id="leftTopControl" style="padding: 5px; background-color:#fff; box-shadow: #101010; margin: 2px;">
                This is Left Top Control.
            </div>
            <div id="leftCenterControl" style="padding: 5px; background-color:#fff; box-shadow: #101010; margin: 2px;">
                This is Left Center Control.
            </div>
            <div id="leftBottomControl" style="padding: 5px; background-color:#fff; box-shadow: #101010; margin: 2px;">
                This is Left Bottom Control.
            </div>
            <div id="bottomRightControl" style="padding: 5px; background-color:#fff; box-shadow: #101010; margin: 2px;">
                This is Bottom Right Control.
            </div>
            <div id="bottomCenterControl" style="padding: 5px; background-color:#fff; box-shadow: #101010; margin: 2px;">
                This is Bottom Center Control.
            </div>
            <div id="bottomLeftControl" style="padding: 5px; background-color:#fff; box-shadow: #101010; margin: 2px;">
                This is Bottom Left Control.
            </div>
            <div id="rightTopControl" style="padding: 5px; background-color:#fff; box-shadow: #101010; margin: 2px;">
                This is Right Top Control.
            </div>
            <div id="rightCenterControl" style="padding: 5px; background-color:#fff; box-shadow: #101010; margin: 2px;">
                This is Right Center Control.
            </div>
            <div id="rightBottomControl" style="padding: 5px; background-color:#fff; box-shadow: #101010; margin: 2px;">
                This is Right Bottom Control.
            </div>
            <div id="topLeftControl" style="padding: 5px; background-color:#fff; box-shadow: #101010; margin: 2px;">
                This is Top Left Control.
            </div>
            <div id="topCenterControl" style="padding: 5px; background-color:#fff; box-shadow: #101010; margin: 2px;">
                This is Top Center Control.
            </div>
            <div id="topRightControl" style="padding: 5px; background-color:#fff; box-shadow: #101010; margin: 2px;">
                This is Top Right Control.
            </div>
            {!! $map['html'] !!}
        </div>
    </div>
</body>
</html>

Geo-fence Example

$polygon = array("25.774,-80.190", "18.466,-66.118", "32.321,-64.757", "25.774,-80.190"); //start and end point should be same
$latlngs = array("-12.043333,-77.028333", "-12.043333,-77.028333");

GMaps::isMarkerInsideGeofence($polygon, $latlngs); //both parameters should be in array
//return will also in array with boolean values like: array(true, false)

Contribution

  • Proxy feature by @grimseer - Nov 22, 2016
  • Fixed to load google api via https by @wissamdagher - Apr 04, 2017
  • Map full screen support by @wissamdagher - Jul 02, 2017
  • Facade namespace fixed by @drehimself - Aug 03, 2017
  • Fixed migration file name by @drehimself - Aug 03, 2017

Thank you for using!

If you like it then click Fork!

Contact me if any query or suggestion you have in support section.

Credits

Library initiative: BioStall

BioStall developed library for codeigniter originally, which you can found at http://biostall.com/laravel-google-maps-v3-api-package/

Conversion into Laravel from codeigniter by: GeneaLabs -- https://github.com/GeneaLabs/Phpgmaps (but it is incomplete)

Comments
  • Geocoding Fix

    Geocoding Fix

    For some reason, geocoding stopped working. Lat, long coordinates are always returning 0, 0. This used to only happen sometimes but is now happening all the time. I'm not sure what changes Google Maps have made.

    Add apiKey to get_lat_long_from_address method fixes the issue.

    opened by drehimself 10
  • Class 'FarhanWazir\GoogleMaps\Facades\GMapsFacade' not found

    Class 'FarhanWazir\GoogleMaps\Facades\GMapsFacade' not found

    I have set up as the guide but got this error:

    Class 'FarhanWazir\GoogleMaps\Facades\GMapsFacade' not found

    However I followed everything and double-checked everything, the problem still persists.

    opened by hanishassim 9
  • issu with the rout

    issu with the rout

    i faced a probleme, "Non-static method FarhanWazir\GoogleMaps\GMaps::initialize() should not be called statically, assuming $this from incompatible context". can u take a look at it, im using laravel 5.4 with php 5*

    opened by BOLYAC 3
  • Issue when loading google maps in https

    Issue when loading google maps in https

    When trying to use the wrapper in https mode the map does not display a simple change in $apiLocation = 'http://maps.googleapis.com/maps/api/js?key='.$this->apiKey.'&sensor='.$this->sensor; to $apiLocation = 'https://maps.googleapis.com/maps/api/js?key='.$this->apiKey.'&sensor='.$this->sensor;

    it will fix the issue

    opened by wissamdagher 3
  • Does this work with Laravel 6.x?

    Does this work with Laravel 6.x?

    Dears,

    I'm doing an app that needs Google Places API. I'm using Laravel 6.x. Does this work good with this version?

    I'm needing this informations:

    • Place ID
    • Latitude
    • Longitude
    • Address (street, number, city, state, country)
    • Place photos
    opened by MiqueiasMaia 2
  • Geocode Caching

    Geocode Caching

    The geocode caching into a Database (MySQL via phpMyAdmin) for Laravel is currently not possible even after resolving the geocode issue that came with change from Google Maps API. Kindly assist

    opened by waynegakuo 2
  • $config['styles'] returns error

    $config['styles'] returns error

    I defined styles in my Controller in this way, following Google Maps documentation:

    $estils = '{
        "featureType": "poi.business",
        "stylers": {"visibility": "off"}
    }';
    $config['styles'] = json_decode($estils, true);
    

    But it returns an error: "Illegal string offset 'definition'".

    uvnyb

    opened by entoniperez 1
  • Error Mixed Content on Heroku

    Error Mixed Content on Heroku

    Mixed Content: The page at 'https://sivar.herokuapp.com/' was loaded over HTTPS, but requested an insecure script 'http://maps.googleapis.com/maps/api/js?key=xyz&sensor=sensor=&v=3'. This request has been blocked; the content must be served over HTTPS.

    opened by wisusdev 1
  • Responsive Maps

    Responsive Maps

    How can I make this maps responsive (Do I have to do it manually or I can use any other responsive maps templates) and how can I get current location of the user.

    opened by softopia-tech 1
  • Add fullScreen control option support

    Add fullScreen control option support

    public $enableFullScreenControl = false;                    // If set to TRUE will enable full screen control
    

    //Added for full screen control if ($this->enableFullScreenControl) { $this->output_js_contents .= ', fullscreenControl: true'; }

    opened by wissamdagher 1
  • Error in namespace GMapsFacade.php

    Error in namespace GMapsFacade.php

    Class 'FarhanWazir\GoogleMaps\Facades\GMapsFacade' not found

    namespace FarhanWazir\GoogleMaps\Facade;

    I solved change in ( GMapsFacade.php ) to :

    namespace FarhanWazir\GoogleMaps\Facades;

    opened by andersondeoliveiramachado 1
  • Your requirements could not be resolved to an installable set of packages.

    Your requirements could not be resolved to an installable set of packages.

    j'ai un problème : Your requirements could not be resolved to an installable set of packages.

    Problem 1 - Installation request for farhanwazir/laravelgooglemaps ^2.3 -> satisfiable by farhanwazir/laravelgooglemaps[2.3, 2.3.0.x-dev, 2.3.1, 2.3.2, 2.3.5, 2.3.6, 2.3.7, 2.3.8, 2.3.9, 2.5.x-dev].

    opened by warzone49 0
  • issues solved please read this

    issues solved please read this

    $data_location = "https://maps.google.com/maps/api/geocode/json?address=".urlencode(utf8_encode($address))."&key=".config('googlemaps.key')."&sensor=".$this->sensor; if ($this->region != "" && strlen($this->region) == 2) { $data_location .= "&region=".$this->region; } D:\xampp\htdocs\googlemap\vendor\farhanwazir\laravelgooglemaps\src\FarhanWazir\GoogleMaps\GMaps.php if map not working first get google api key is vailed and enable map service and for direction enable direction services and this package working with price plain of map and after these things map not still working then please go to D:\xampp\htdocs\googlemap\vendor\farhanwazir\laravelgooglemaps\src\FarhanWazir\GoogleMaps\GMaps.php and replace code $data_location = "https://maps.google.com/maps/api/geocode/json?address=".urlencode(utf8_encode($address))."&key=".config('googlemaps.key')."&sensor=".$this->sensor; if ($this->region != "" && strlen($this->region) == 2) { $data_location .= "&region=".$this->region; } if working on server enable file_get_contents and any js changes of google map js related file is D:\xampp\htdocs\googlemap\vendor\farhanwazir\laravelgooglemaps\src\FarhanWazir\GoogleMaps\GMaps.php

    for help http://biostall.com/demos/google-maps-v3-api-codeigniter-library/

    https://www.youtube.com/watch?v=LTJ5t3fXoXU&t=699s

    opened by faisalsehar786 3
  •  - laravel/framework 5.0.x-dev requires ext-mcrypt * -> the requested PHP extension mcrypt is missing from your system.

    - laravel/framework 5.0.x-dev requires ext-mcrypt * -> the requested PHP extension mcrypt is missing from your system.

    Hi when i try to install in PHP 7.2.19 i found this

    • laravel/framework 5.0.x-dev requires ext-mcrypt * -> the requested PHP extension mcrypt is missing from your system.

    To enable extensions, verify that they are enabled in your .ini files: - C:\laragon\bin\php\php-7.2.19-Win32-VC15-x64\php.ini You can also run php --ini inside terminal to see which files are used by PHP in CLI mode.

    Installation failed, reverting ./composer.json to its original content.

    i read about this :

    This feature was DEPRECATED in PHP 7.1.0, and REMOVED in PHP 7.2.0.

    Alternatives to this feature include:

    Sodium (available as of PHP 7.2.0) OpenSSL

    Can you do some FIX to this can work with Laravel 6 in php 7.2

    Kind Regards

    opened by josemdwt 1
Releases(2.3.9)
Owner
Farhan Wazir
Farhan Wazir
Collection of Google Maps API Web Services for Laravel

Collection of Google Maps API Web Services for Laravel Provides convenient way of setting up and making requests to Maps API from Laravel application.

Alexander Pechkarev 467 Jan 5, 2023
MapServer and PHP-MapScript application to create publication-quality maps

SimpleMappr Installation and Configuration SimpleMappr, http://www.simplemappr.net is a web-based application that produces publication-quality geogra

David Shorthouse 28 Mar 17, 2022
A plugin for Blessing Skin Server that can let you display Google Ads with Google AdSense in the website.

A plugin for Blessing Skin Server that can let you display Google Ads with Google AdSense in the website.

Big_Cake 2 Jan 25, 2022
Laravel-tagmanager - An easier way to add Google Tag Manager to your Laravel application.

Laravel TagManager An easier way to add Google Tag Manager to your Laravel application. Including recommended GTM events support. Requirements Laravel

Label84 16 Nov 23, 2022
Manage self-hosted Google Fonts in Laravel apps

This package makes self-hosting Google Fonts as frictionless as possible for Laravel users. To load fonts in your application, register a Google Fonts embed URL and load it with the @googlefonts Blade directive.

Spatie 386 Dec 19, 2022
Automatically disable Google's FLoC in Laravel apps

Automatically disable Google's FLoC in Laravel apps This package will automatically disable Google's FLoC. Support us We invest a lot of resources int

Spatie 68 Oct 21, 2022
Google Cloud Storage filesystem driver for Laravel

Google Cloud Storage filesystem driver for Laravel Google Cloud Storage filesystem driver for Laravel. This started as a fork from Superbalist/laravel

Spatie 88 Dec 16, 2022
Laravel real-time CRUD using Google Firebase.

Laravel real-time CRUD using Google Firebase.

Fadi Mathlouthi 1 Oct 22, 2021
a Google API v3 wrapper for Laravel 4.x

A Google API v3 wrapper for Laravel 4 This package enables a Laravel flavoured way to manage Google services through its API interface (v3) Installati

null 4 Nov 29, 2022
Laravel 4.* and 5.* service providers to handle PHP errors, dump variables, execute PHP code remotely in Google Chrome

Laravel 4.* service provider for PHP Console See https://github.com/barbushin/php-console-laravel/releases/tag/1.2.1 Use "php-console/laravel-service-

Sergey 73 Jun 1, 2022
Hcaptcha & Google ReCaptcha Solution for Laravel Framework

Laravel Captcha is a wrapper around HCaptcha & Google Recaptcha. It provides very easy-to-use Facade, Validation Rule, and blade directives.

Rahul Dey 47 Oct 27, 2022
Adds phone number functionality to Laravel based on the PHP port of Google's libphonenumber API by giggsey.

Laravel Phone Adds phone number functionality to Laravel based on the PHP port of Google's libphonenumber API by giggsey. Table of Contents Demo Insta

null 2.1k Jan 2, 2023
Lavacharts is a graphing / charting library for PHP 5.4+ that wraps Google's Javascript Chart API.

Lavacharts 3.1.12 Lavacharts is a graphing / chart library for PHP5.4+ that wraps the Google Chart API. Stable: Dev: Developer Note Please don't be di

Kevin Hill 616 Dec 17, 2022
:passport_control: Helper for Google's new noCAPTCHA (reCAPTCHA v2 & v3)

noCAPTCHA (new reCAPTCHA) By ARCANEDEV© What is reCAPTCHA? reCAPTCHA is a free service that protects your site from spam and abuse. It uses advanced r

ARCANEDEV 341 Nov 19, 2022
Adds phone number functionality to TYPO3 based on the PHP port of Google's libphonenumber API by giggsey

TYPO3 Phone Adds phone number functionality to TYPO3 based on the PHP port of Google's libphonenumber API by giggsey. Installation composer require si

Simon Schaufelberger 3 Oct 25, 2022
Jetstrap is a lightweight laravel 8 package that focuses on the VIEW side of Jetstream / Breeze package installed in your Laravel application

A Laravel 8 package to easily switch TailwindCSS resources generated by Laravel Jetstream and Breeze to Bootstrap 4.

null 686 Dec 28, 2022
A Laravel chat package. You can use this package to create a chat/messaging Laravel application.

Chat Create a Chat application for your multiple Models Table of Contents Click to expand Introduction Installation Usage Adding the ability to partic

Tinashe Musonza 931 Dec 24, 2022
This package provides extended support for our spatie/enum package in Laravel.

Laravel support for spatie/enum This package provides extended support for our spatie/enum package in Laravel. Installation You can install the packag

Spatie 264 Dec 23, 2022
Testbench Component is the de-facto package that has been designed to help you write tests for your Laravel package

Laravel Testing Helper for Packages Development Testbench Component is the de-facto package that has been designed to help you write tests for your La

Orchestra Platform 1.9k Dec 29, 2022