laravel - 使用 laravel 中的传单从数据库中标记位置
问题描述
我的数据库中有一个名为 location 的表,它由纬度和经度组成,我需要使用传单开放街道地图在地图上标记它们。我不知道我该怎么做。到目前为止,我只能手动标记。如果您有任何资源,我可以从中获得想法,请帮助
@extends('master');
@section('content');
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css"
integrity="sha512-xodZBNTC5n17Xt2atTPuE1HxjVMSvLVW9ocqUKLsCC5CXdbqCmblAshOMAS6/keqq/sMZMZ19scR4PsZChSR7A=="
crossorigin=""/>
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"
integrity="sha512-XQoYMqMTK8LvdxXYG3nZ448hOEQiglfqkJs1NOQV44cWnUrBc8PkAOcXy20w0vlaXaVUearIOBhiXZ5V3ynxwA=="
crossorigin=""></script>
<style>
#map {position: absolute; top: 0; bottom: 0; left: 0; right: 0}
</style>
<div id="map"></div>
<script>
var map = L.map('map').setView([51.505, -0.09], 13);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a
href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>
contributors'
}).addTo(map);
L.marker([19.0971904, 72.8891392]).addTo(map)
.bindPopup('A pretty CSS3 popup.<br> Easily customizable.')
.openPopup();
</script>
@endsection
解决方案
看起来您可能需要使用 Ajax
<script>
$(function(){
$.ajax({
url: "/leaflect",
type: 'GET',
success: function(data) {
$.each(data, function( key, value ) {
L.marker([value.latitude, value.longitude]).addTo(map)
.bindPopup('A pretty CSS3 popup.<br> Easily customizable.')
.openPopup();
})
},
error: function(data) {
}
});
})
</script>
路线会像
Route::get('leaflect',[ControllerName@methodName]);
控制器方法就像
public function methodName(){
return Model::get();
}
推荐阅读
- c - 将数据复制到 C 中结构内部的字符串会导致分段错误
- python - 终端变得无响应
- sql - ALTER FUNCTION 重建了哪些元数据、统计信息、计划?
- sql-server - 查看自上次运行 proc 以来创建了多少个面板
- oracle - 将 Devart Oracle 提供程序与 OData 一起使用时出现 DataServiceException
- android - TimePicker - 如何设置上午或下午?
- azure - 为 redshift 和数据工厂开放 IP 地址
- java - 从认可的目录中使用 log4j2
- animation - 如何在 touchdesigner 中从一条线创建两条线?
- angular - 尝试打印 HTML 的画布