farhanwazir / laravelgooglemaps

Laravel Google Maps Package
MIT License
153 stars 112 forks source link

issu with the rout #16

Closed BOLYAC closed 6 years ago

BOLYAC commented 6 years ago

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*

farhanwazir commented 6 years ago

For now you can use it is dynamic call of laravel as illustrated below:

class TestController extends Controller { protected $gmaps; public function __construct(GMaps $gmaps){ $this->gmaps = $gmaps;} }

richardcmg7 commented 6 years ago

Hey, Thank you for your app, When I try to put a function with a controller I receive the same error I do the next, in route\Web.php Route::get('/map', 'MapController@index'); in "MapController" public function index() { $this->gmaps = $gmaps; $config['center'] = 'Miami, US'; $config['zoom'] = 13; $config['map_height'] = '600px'; $config['geocodeCaching'] = true; $config['scrollwheel'] = false; GMaps::initialize($config); //add maker $marker['position'] = 'Adress XXX'; $marker['infowindow_content'] = 'Adress XXX'; $marker['icon']='http://maps.google.com/mapfiles/ms/micons/yellow-dot.png'; GMaps::add_marker($marker); $map = GMaps::create_map(); return view('/home')->with('map',$map); } Im new in LAravel and some thing difficult to me, but I aprecciate any suggestion.. Richard

HeshanDSilva commented 5 years ago

Hey, i fixed the problem by creating a object of GMaps class when calling constructor. here i attached how i did

public function showMap() { $device = Device::all(); $lat = '6.9271'; $long = '79.9612'; $config = array(); $config['center'] = '6.9271, 79.8612'; $config['geocodeCaching'] = true; $gmaps = new GMaps($config); $gmaps->initialize($config); foreach($device as $devices){ $marker['position']=$devices->lattitude.','.$devices->longtitude; $marker['icon']='/Google Maps Markers/blue_MarkerA.png'; $gmaps->add_marker($marker); } $map = $gmaps->create_map(); echo $map['js']; echo $map['html']; }