【发布时间】:2015-11-15 17:05:44
【问题描述】:
我是 json 和 laravel 的新手,我想提出我的问题。
我有一个名为 dealer_address 的数据库表,其中包含 id、address、state、pin、city。
我用一些地址加载地图的javascript是:
<script type="text/javascript">
$(function(){
$('#test1').gmap3({
map:{
options:{
center:[46.578498,2.457275],
zoom: 5
}
},
marker:{
values:[
{latLng:[48.8620722, 2.352047], data:"Paris !"},
{address:
$.ajax({
url: '/maps2/',
type: 'get',
data: {_token: CSRF_TOKEN},
dataType: 'JSON',
success: function (results) {
console.log(results);
}
})}
],
options:{
draggable: false
},
events:{
mouseover: function(marker, event, context){
var map = $(this).gmap3("get"),
infowindow = $(this).gmap3({get:{name:"infowindow"}});
if (infowindow){
infowindow.open(map, marker);
infowindow.setContent(context.data);
} else {
$(this).gmap3({
infowindow:{
anchor:marker,
options:{content: context.data}
}
});
}
},
mouseout: function(){
var infowindow = $(this).gmap3({get:{name:"infowindow"}});
if (infowindow){
infowindow.close();
}
}
}
}
})
});
</script>
但是,我想根据数据库结果在地图上显示地址。
public function ShowData()
{
$location = '700016';
$results = DB::table('dealer_address')
->where('dealer_address.city', 'LIKE', '%'.$location.'%')
->orWhere('dealer_address.pincode', 'LIKE', '%'.$location.'%')
->orWhere('dealer_address.state', 'LIKE', '%'.$location.'%')
->get();
dd($results);
return View::make('/maps2')->with('data', json_encode($results));
}
我的dd($results) 工作正常。我需要在我的 javascript 中更改什么位置和什么来传递这个 json ?
【问题讨论】:
标签: javascript php json google-maps laravel