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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度