当我在浏览器中显示空白页面时,尝试使用javascript通过blade.php文件显示Google Map。这是控制器代码
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="header">
<a class="head">Title</a>
<a class="test head">
<label for="tab1" id="label1" class="label">Tab 1</label>
</a>
<a class="test head">
<label for="tab2" id="label2" class="label">Tab 2</label>
</a>
<a class="test head">
<label for="tab3" id="label3" class="label">Tab 3</label>
</a>
<a class="test head">
<label for="tab4" id="label4" class="label">Tab 4</label>
</a>
</div>
}
和blade.php代码
class ItemsController extends Controller {
public function map(){
$items = Item::all();
return view('items.map',compact('items'));
}
数据库迁移文件在这里:
@extends('app')
@section('content')
<div class="container">
<div class="row">
<div id="map-canvas"></div>
</div>
</div>
<script type="text/javascript">
var mapOptions ={
zoom :4,
center:new google.maps.LatLng({{$items[0]->location}})
}
var map = new google.maps.Map(document.getElementById("map-canvas"),mapOptions);;
@foreach($items as $item)
var marker{{$item->id}}=new google.maps.Marker({
position: new google.maps.LatLng({{$item->location}}),
map:map,
title:"{{$item->title}}"
});
@endforeach
</script>