PHP生成的谷歌地图JSON:一个小小的谜团

时间:2022-04-08 10:07:43

I am using a PHP script (this one) to generate a JSON file for a Google Map.

我正在使用PHP脚本(这个)为Google Map生成JSON文件。

this is the PHP code (note: I am using Laravel):

这是PHP代码(注意:我正在使用Laravel):

<?php

$query = "SELECT id, info, lat, lng FROM places";
$results = DB::select($query);

$myLocations = array();
$i = 0;

$testLoc = array('loc95' => array( 'lat' => 15, 'lng' => 144.9634 ));

foreach ($results as $result)
{
  $myLocation = array(
    'loc'.++$i => array(
    'lat' => round((float)$result->lat, 4),
    'lng' => round((float)$result->lng, 4)
  ));
  $myLocations += $myLocation;
}

$myLocations += $testLoc;

echo json_encode($myLocations);
?>

and this is the output:

这是输出:

{"loc1":{"lat":45.4833,"lng":9.1854},"loc2":{"lat":45.4867,"lng":9.1648},"loc3":{"lat":45.4239,"lng":9.1652},"loc95":{"lat":15,"lng":144.9634}}

ok. the script I use to put the JSON data in a Google Map, unfortunately, keeps ignoring any data coming from the MySQL database, and shows only the test data place(s). I have tried to swap data, to put in test data the same info found in database... nothing, I keep seeing only the test data.

好。不幸的是,我用来将JSON数据放在Google Map中的脚本一直忽略来自MySQL数据库的任何数据,并且只显示测试数据位置。我试图交换数据,将测试数据放入数据库中找到的相同信息......没有,我只看到测试数据。

but, really: I cannot figure out why. What am I missing... ?

但是,真的:我无法弄清楚为什么。我错过了什么......?

1 个解决方案

#1


0  

You wrote that you're using another script and that the other script only shows the testlocations on google maps.

您写道,您正在使用其他脚本,而另一个脚本仅显示Google地图上的测试位置。

My guess is that you didn't update the other script to your needs, specifically my crystal ball is telling me that you still have this line in there:

我的猜测是你没有更新其他脚本以满足你的需求,特别是我的水晶球告诉我你还有这条线:

setMarkers(locs);//Create markers from the initial dataset served with the document.

In your question you only showed the part which worked and I agree, but you only mentioned that "something else" isn't working. If you want an answer for that part, try reprashing your question and include the parts which cause you problems.

在你的问题中,你只展示了哪个部分有效,我同意,但你只提到“别的东西”不起作用。如果您想要该部分的答案,请尝试重新解决您的问题并包括导致您出现问题的部分。

#1


0  

You wrote that you're using another script and that the other script only shows the testlocations on google maps.

您写道,您正在使用其他脚本,而另一个脚本仅显示Google地图上的测试位置。

My guess is that you didn't update the other script to your needs, specifically my crystal ball is telling me that you still have this line in there:

我的猜测是你没有更新其他脚本以满足你的需求,特别是我的水晶球告诉我你还有这条线:

setMarkers(locs);//Create markers from the initial dataset served with the document.

In your question you only showed the part which worked and I agree, but you only mentioned that "something else" isn't working. If you want an answer for that part, try reprashing your question and include the parts which cause you problems.

在你的问题中,你只展示了哪个部分有效,我同意,但你只提到“别的东西”不起作用。如果您想要该部分的答案,请尝试重新解决您的问题并包括导致您出现问题的部分。