获取经纬度
Get lat and long
我正在构建一个函数来从 google 地图 link 中获取纬度和经度。我让它工作了它应该如何工作它应该如何工作:
public function getLocaties(){
$locations = $this->getObjects(68);
foreach ($locations as $location) {
$latAndLong = $this->getLatAndLong($locations ['data']['link']);
$location['data']['latiude'] = $latAndLong['lat'];
$location['data']['longtitude'] = $latAndLong['long'];
var_dump($locatie);
}
return $locaties;
}
现在 var_dump 打印以下内容:
`array(4) {
["id"]=>
string(2) "69"
["type_id"]=>
string(2) "24"
["parent_id"]=>
string(2) "68"
["data"]=>
array(13) {
["object_name"]=>
string(28) "Hajé restaurant de Taveerne"
["object_createdate"]=>
string(10) "1584437106"
["object_createuser"]=>
string(3) "{4}"
["object_read"]=>
string(3) "{4}"
["object_write"]=>
string(3) "{4}"
["object_delete"]=>
string(3) "{4}"
["object_update"]=>
string(3) "{4}"
["object_display"]=>
string(4) "tree"
["object_priority"]=>
string(1) "1"
["data_html"]=>
string(80) "<p>Hajé de Taveerne Oostvaardersdijk 01-09 8244 PA Lelystad Nederland</p>"
["link"]=>
string(162) "https://www.google.com/maps/place/Haj%C3%A9+restaurant+de+Taveerne/@52.522116,5.437504,12z/data=!4m5!3m4!1s0x0:0x2a85d0586811bc85!8m2!3d52.522116!4d5.437504?hl=nl"
["latiude"]=>
array(1) {
[0]=>
string(9) "52.522116"
}
["longtitude"]=>
array(1) {
[0]=>
string(8) "5.437504"
}
}
}`
这是完美的,但是当我在 index.php 中调用该函数时,它从数组中删除了纬度和经度:
$locations = $blokken->getLocaties();
var_dump($locations);
var_dump 打印如下:
`array(1) {
[0]=>
array(4) {
["id"]=>
string(2) "69"
["type_id"]=>
string(2) "24"
["parent_id"]=>
string(2) "68"
["data"]=>
array(11) {
["object_name"]=>
string(28) "Hajé restaurant de Taveerne"
["object_createdate"]=>
string(10) "1584437106"
["object_createuser"]=>
string(3) "{4}"
["object_read"]=>
string(3) "{4}"
["object_write"]=>
string(3) "{4}"
["object_delete"]=>
string(3) "{4}"
["object_update"]=>
string(3) "{4}"
["object_display"]=>
string(4) "tree"
["object_priority"]=>
string(1) "1"
["data_html"]=>
string(80) "<p>Hajé de Taveerne Oostvaardersdijk 01-09 8244 PA Lelystad Nederland</p>"
["link"]=>
string(162) "https://www.google.com/maps/place/Haj%C3%A9+restaurant+de+Taveerne/@52.522116,5.437504,12z/data=!4m5!3m4!1s0x0:0x2a85d0586811bc85!8m2!3d52.522116!4d5.437504?hl=nl"
}
}
}`
我有点困惑为什么我的索引中没有得到纬度和经度
当您迭代 $locations
时,$location
变量包含在循环中 - 您不会写回 $locations
.
尝试添加对 $location
的引用
public function getLocaties(){
$locations = $this->getObjects(68);
foreach ($locations as &$location) {
$latAndLong = $this->getLatAndLong($locations ['data']['link']);
$location['data']['latiude'] = $latAndLong['lat'];
$location['data']['longtitude'] = $latAndLong['long'];
var_dump($locatie);
}
return $locaties;
}
我正在构建一个函数来从 google 地图 link 中获取纬度和经度。我让它工作了它应该如何工作它应该如何工作:
public function getLocaties(){
$locations = $this->getObjects(68);
foreach ($locations as $location) {
$latAndLong = $this->getLatAndLong($locations ['data']['link']);
$location['data']['latiude'] = $latAndLong['lat'];
$location['data']['longtitude'] = $latAndLong['long'];
var_dump($locatie);
}
return $locaties;
}
现在 var_dump 打印以下内容:
`array(4) {
["id"]=>
string(2) "69"
["type_id"]=>
string(2) "24"
["parent_id"]=>
string(2) "68"
["data"]=>
array(13) {
["object_name"]=>
string(28) "Hajé restaurant de Taveerne"
["object_createdate"]=>
string(10) "1584437106"
["object_createuser"]=>
string(3) "{4}"
["object_read"]=>
string(3) "{4}"
["object_write"]=>
string(3) "{4}"
["object_delete"]=>
string(3) "{4}"
["object_update"]=>
string(3) "{4}"
["object_display"]=>
string(4) "tree"
["object_priority"]=>
string(1) "1"
["data_html"]=>
string(80) "<p>Hajé de Taveerne Oostvaardersdijk 01-09 8244 PA Lelystad Nederland</p>"
["link"]=>
string(162) "https://www.google.com/maps/place/Haj%C3%A9+restaurant+de+Taveerne/@52.522116,5.437504,12z/data=!4m5!3m4!1s0x0:0x2a85d0586811bc85!8m2!3d52.522116!4d5.437504?hl=nl"
["latiude"]=>
array(1) {
[0]=>
string(9) "52.522116"
}
["longtitude"]=>
array(1) {
[0]=>
string(8) "5.437504"
}
}
}`
这是完美的,但是当我在 index.php 中调用该函数时,它从数组中删除了纬度和经度:
$locations = $blokken->getLocaties();
var_dump($locations);
var_dump 打印如下:
`array(1) {
[0]=>
array(4) {
["id"]=>
string(2) "69"
["type_id"]=>
string(2) "24"
["parent_id"]=>
string(2) "68"
["data"]=>
array(11) {
["object_name"]=>
string(28) "Hajé restaurant de Taveerne"
["object_createdate"]=>
string(10) "1584437106"
["object_createuser"]=>
string(3) "{4}"
["object_read"]=>
string(3) "{4}"
["object_write"]=>
string(3) "{4}"
["object_delete"]=>
string(3) "{4}"
["object_update"]=>
string(3) "{4}"
["object_display"]=>
string(4) "tree"
["object_priority"]=>
string(1) "1"
["data_html"]=>
string(80) "<p>Hajé de Taveerne Oostvaardersdijk 01-09 8244 PA Lelystad Nederland</p>"
["link"]=>
string(162) "https://www.google.com/maps/place/Haj%C3%A9+restaurant+de+Taveerne/@52.522116,5.437504,12z/data=!4m5!3m4!1s0x0:0x2a85d0586811bc85!8m2!3d52.522116!4d5.437504?hl=nl"
}
}
}`
我有点困惑为什么我的索引中没有得到纬度和经度
当您迭代 $locations
时,$location
变量包含在循环中 - 您不会写回 $locations
.
尝试添加对 $location
public function getLocaties(){
$locations = $this->getObjects(68);
foreach ($locations as &$location) {
$latAndLong = $this->getLatAndLong($locations ['data']['link']);
$location['data']['latiude'] = $latAndLong['lat'];
$location['data']['longtitude'] = $latAndLong['long'];
var_dump($locatie);
}
return $locaties;
}