alexpechkarev / google-maps

Collection of Google Maps API Web Services for Laravel
https://alexpechkarev.github.io/google-maps/
MIT License
520 stars 115 forks source link

Unable to find config file on controller #83

Closed ferrysoto closed 4 years ago

ferrysoto commented 4 years ago

I see your example on docs git directory, but you no have the "use GoogleMaps\Facade\GoogleMapsFacade;" in your controller.

I try to use for add a map in my dashboard, but can't use because not understand how use in controller to return the map position and insert map on view.

Thanks

KasunAssetDidital commented 4 years ago

hi @ferrysoto

some times this could be help for you `<?php

namespace App\Http\Controllers;

use GoogleMaps\GoogleMaps;

class MapController extends Controller { public function data() { $response = \GoogleMaps::load('directions') ->setParam([ 'origin' => 'Dublin, Ireland', 'destination' => 'Paris, France', 'mode' => 'driving', 'waypoints' => 'optimize:true|Nottingham, United Kingdom', // can also be given as an array ['Charlestown,MA','Lexington,MA'] 'alternatives' => true, 'avoid' => 'ferries', 'units' => 'metric', 'region' => 'GB', 'departure_time' => 'now', ]) ->get(); return json_decode($data,true);

this returns map response

the print path on google map including destination and origin marker, this is a code snippet from my project Client Side

`var initMap = (routes) => { if (routes) { let resp = routes['routes'][0]['legs'][0]; map = new google.maps.Map(document.getElementById('map'), { center: { lat: routes['origin']['lat'], lng: routes['origin']['lng'] }, zoom: 8 }); var origin, destination = new google.maps.LatLng(); origin = routes['origin']; destination = routes['destination'];

        new google.maps.Marker({
            position: origin,
            map: map
        });
        new google.maps.Marker({
            position: destination,
            map: map
        });
        var flightPlanCoordinates = routes['routes'][0]['overview_polyline']['points'];
        var bounds = new google.maps.LatLngBounds();
        bounds.extend(origin);
        bounds.extend(destination);
        map.fitBounds(bounds);

    } else {
        if (navigator.geolocation) {
            navigator.geolocation.getCurrentPosition(position => {
                let location = {
                    lat: position.coords.latitude,
                    lng: position.coords.longitude
                };
                map.setCenter(location);
                map.getCenter();
            });
        }
        map = new google.maps.Map(document.getElementById('map'), {
            center: {
                lat: -34.397,
                lng: 150.644
            },
            zoom: 8
        });
        var flightPlanCoordinates = [];
    }
    var flightPath = new google.maps.Polyline({
        path: flightPlanCoordinates,
        geodesic: false,
        strokeColor: '#031F6E',
        strokeOpacity: 1,
        strokeWeight: 2
    });
    flightPath.setMap(map);
}

`
alexpechkarev commented 4 years ago

Hi @ferrysoto,

Apologies for the late response.

I hope @KasunAssetDidital answer above gives you enough details to answer your question.

Regards, Alexander

ferrysoto commented 4 years ago

Hi,

@alexpechkarev no problem, thank you very much guys, @KasunAssetDidital for your response, fix it with your code solution.

Regards, Ferran Herrero