drvntaomy06331839 2017-06-20 16:27
浏览 39
已采纳

如何将Google地图坐标数组存储到php变量中?

I am trying to grab coordinates from an array to add to a Google map to output my polygons.

And I am running into some difficulty in trying to echo out my array ($ArrayCoords) as a string to store into a variable.

I have this array which consist of multiple lat and lng coordinates as well as a zoom:

$ArrayCoords = get_field('Array_Coords');
print_r($ArrayCoords); 

/*   Print out as:

 [draw_map] => Array
            (
                [coords] => Array
                    (
                        [0] => Array
                            (
                                [lat] => 38.928713698662
                                [lng] => -94.537423253059
                            )

                        [1] => Array
                            (
                                [lat] => 38.927679421508
                                [lng] => -94.537782669067
                            )

                        [2] => Array
                            (
                                [lat] => 38.928038315258
                                [lng] => -94.53973531723
                            )

                        [3] => Array
                            (
                                [lat] => 38.928171856655
                                [lng] => -94.54069018364
                            )

                        [4] => Array
                            (
                                [lat] => 38.928215341202
                                [lng] => -94.541194438934
                            )

                        [5] => Array
                            (
                                [lat] => 38.929258624074
                                [lng] => -94.541215896606
                            )

                    )

                    [zoom] => 13
         )
*/

I am trying to turn this array to store into a variables ($latLngCoords and $Zoom) which will echo as:

echo $latLngCoords;

/*
38.928713698662, -94.537423253059
38.927679421508, -94.537782669067
....and so on..
*/

echo $Zoom;

// 13

I am not sure how to do this.

  • 写回答

1条回答 默认 最新

  • doupu3635 2017-06-20 18:37
    关注

    Thanks to all, I am very sorry if my question seemed unclear :( but I think I figured out my answer using a while loop:

    $Zoom = $ArrayCoords[zoom];
    $array = $ArrayCoords[coords];
    $arrayCount = count($array) - 1;
    //arrayCount is 6, but because of array starting at 0, we need to minus -1
    
    $i=0;
    while($i <= $arrayCount)
      {
      $latLngCoords .= $array[$i][lat] . ", " . $array[$i][lng] . "<br>";
    
      $i++;
    
      }
    
    echo $latLngCoords;
    
    echo $Zoom;
    
     //print_r($array);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 Yolov5训练报错
  • ¥15 Unity发布gzip压缩的webgl之后让浏览器可以正常显示画面
  • ¥15 有没有人知道这种提示怎么关?现在不做ts项目了不知道咋关了,求解,现在我以前的js项目都是这种提示了
  • ¥15 为什么mysql做了碎片化处理data_free还是很高
  • ¥15 single positional indexer is out-of-bounds
  • ¥15 LSTM 模型数据量需要多少?
  • ¥15 mysql数据抓包开发报表
  • ¥15 linux系统下安装office打不开
  • ¥20 rsync脚本分发错误,文件不齐全
  • ¥15 labview顺序结构与时间延时