创建谷歌地图
问题描述:
我试图初始化一个新的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>
看看这个。 https://github.com/bradcornford/Googlmapper – Danieboy