慕虎7371278
由于您的脚本位于 Laravel 刀片内部,因此您可以将 PHP 变量经度和纬度分配给 javascript 变量。//Suppose your PHP variable name is $loc having lat and long attribute<script> let provided_longitude = <?php echo $loc->long; ?>; let provided_latitude = <?php echo $loc->lat; ?>; console.log(provided_longitude, provided_latitude);</script>现在您可以在谷歌地图中使用提供的经度和提供的纬度。example.blade.php 中的iframe 示例<iframe width="600" height="450" frameborder="0" style="border:0" src="https://www.google.com/maps/embed/v1/place?key=YOUR_API_KEY &q={{$loc->lat}},{{$loc->long}}" allowfullscreen></iframe>编辑 1显示表格中的标记(例如:具有列经度、纬度的订单)//在你的控制器里面$orders = Order::select('id', 'longitude', 'latitude');return view('your.page', [ 'orders' => $orders]); //在你的/page.blade.php里面<div id="map" style="width: 500px; height: 400px;"></div>...<script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script><script type="text/javascript"> var locations = <?php echo $orders ?>; var map = new google.maps.Map(document.getElementById('map'), { zoom: 10, center: new google.maps.LatLng(-33.92, 151.25), mapTypeId: google.maps.MapTypeId.ROADMAP }); var infowindow = new google.maps.InfoWindow(); var marker, i; for (i = 0; i < locations.length; i++) { marker = new google.maps.Marker({ position: new google.maps.LatLng(locations[i]['latitude'], locations[i]['longitude']), map: map }); }</script>