【发布时间】:2016-02-03 01:30:56
【问题描述】:
我正在尝试使用 tutorial 和 Laravel 5 制作商店定位器应用程序。这些问题中的人 Here 和 Here 似乎正在使用 @foreach 循环和其他刀片模板语言来运行他们的 lat/长坐标。他们是怎么做到的?
当我的地图代码在 js 文件中时,我基本上不知道如何使用刀片循环坐标?这怎么可能?我做错了什么吗?
我正在用一个包含以下代码的 js 文件 (maps.js) 显示我的地图:
function initialize() {
var map_canvas = document.getElementById('map');
// Initialise the map
var map_options = {
center: location,
zoom: 10,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(map_canvas, map_options)
// Put all locations into array
var locations = [
@foreach ($articles as $article)
[ {{ $article->lat }}, {{ $article->lng }} ]
@endforeach
];
for (i = 0; i < locations.length; i++) {
var location = new google.maps.LatLng(locations[i][0], locations[i][1]);
var marker = new google.maps.Marker({
position: location,
map: map,
});
}
// marker.setMap(map); // Probably not necessary since you set the map above
}
但显然这被困在@foreach 行。
PS:如果有人使用 Laravel 5 遵循本教程,我将不胜感激这部分的任何信息:使用 PHP 输出 XML。
【问题讨论】:
标签: javascript php google-maps laravel