gpt4 book ai didi

php - 拉拉维尔 : change the contents of the variable with the database field

转载 作者:行者123 更新时间:2023-11-29 17:20:18 25 4
gpt4 key购买 nike

我有代码 Laravel在代码中,我有变量 $latitude1 和 longitude1,并且该变量具有静态内容,例如“108.2251681”。

$maps = Gmaps_Geocache::all();

$latitude1 = -7.325374900000001;
$longitude1 = 108.2251681;

$latitude2 = -7.331842799999999;
$longitude2 = 108.2237382;

$dataJson = file_get_contents("https://maps.googleapis.com/maps/api/distancematrix/json?units=metric&origins=".$latitude1.",".$longitude1."&destinations=".$latitude2.",".$longitude2."&key=AIzaSyCyUBu8OPh0adMWbL9McFMMDqJA9UB7jes");

如何更改变量的内容“108.2251681”并立即从字段数据库中获取?

最佳答案

我正在解决它,我把它放在 View Blade 中

<table border="1">
<tr>
<th>Address</th>
<th>Latitude</th>
<th>Longitude</th>
<th>Jarak</th>
</tr>
@foreach($maps as $m)
<tr>
@php
$latitude1 = -7.325374900000001;;
$longitude1 = 108.2251681;

$latitude2 = $m->latitude;
$longitude2 = $m->longitude;

$dataJson = file_get_contents("https://maps.googleapis.com/maps/api/distancematrix/json?units=metric&origins=".$latitude1.",".$longitude1."&destinations=".$latitude2.",".$longitude2."&key=AIzaSyCyUBu8OPh0adMWbL9McFMMDqJA9UB7jes");

$json = json_decode($dataJson);
$nilaiJarak = $json->rows[0]->elements[0]->distance->text;
@endphp
<td>{{ $m->address }}</td>
<td>{{ $m->latitude }}</td>
<td>{{ $m->longitude }}</td>
<td>{{ $nilaiJarak }}</td>
</tr>
@endforeach
</table>

关于php - 拉拉维尔 : change the contents of the variable with the database field,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51296257/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com