创建Google地图

时间:2016-07-24 14:49:29

标签: php google-maps laravel view routes

我正在尝试初始化指向某个位置的新 Gmap ,该位置将显示在我的视图中。当我检查我的布局时,它会正常加载,但它不会创建一个地图。我的想法是将我的坐标保存为数据库中的字符串。非常感谢任何帮助。这是我的路线功能:

<?php

use Appitventures\Phpgmaps\Phpgmaps as Gmaps;


Route::get('/', array( 'http' , 'as' => 'conf.show' , 'uses' => function($slug)
{
    $conference = \Events\Models\Event::where('slug' , '=' , $slug )->first();

       $view = [
            'conference'    =>  $conference

        ];

    $theme = \Theme::uses('conference'); 
    $template = $conference->eventable->template;

    $tmpFile = $template ? "landingtemplates.$template.default" : "landing";

    // Add map location to conference

    $loc = $conference->gmap_location;
    if(strpos($loc, ',')) {
    $location = explode(",", $loc);
        $config = array();
        $config['center'] = $location[0].', '.$location[1];
        $config['zoom'] = 17;
        $gmaps = new Gmaps();
        $gmaps->apiKey  = '';
        $gmaps->https   = TRUE;
        $gmaps->initialize($config);

            // set up the marker ready for positioning
            // once we know the users location
        $marker = array();
        $marker['position'] = $location[0].', '.$location[1];
        $gmaps->add_marker($marker);


        $map = $gmaps->create_map();
        Theme::set('map', $map);


    }
    return $theme->load('workbench.events.src.views.conf.'.$tmpFile, $view)->render();



}));
?>

这是我的视图

<div class="container map" id="map">

                @if($conference->gmap_location)
                <?php $map = Theme::get('map'); ?>
                 {{ $map['html']  }}
                @endif

</div>

1 个答案:

答案 0 :(得分:0)

这似乎是您正在寻找的。

https://github.com/bradcornford/Googlmapper