php
  • arrays
  • json
  • geojson
  • 2017-12-15 17 views 0 likes 
    0

    나는 그것의 왼쪽에서 무엇을 내 머리카락을 당길거야. geoJSON 배열에서 좌표 및 지오 펜스 유형 (이 경우에는 다각형)을 가져와야합니다. 아래는 내가 가지고있는 것입니다. 미리 감사드립니다. 래리. 오직 하나의 "기능"거기 가정PHP의 geoJSON 다차원 배열에서 좌표 검색

    $str='{"type":"FeatureCollection","features":[{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[-77.0416259765625,38.89530825492018],[-77.03295707702638,38.89351294034218],[-77.03700184822084,38.89317057287496],[-77.0323669910431,38.892193563954955],[-77.04053163528442,38.89286160569515],[-77.0416259765625,38.89530825492018]]]}}]}'; 
    
    $json = json_decode($str); 
    echo'<pre>';print_r($json);echo'</pre>'; 
    $set = 1; 
    foreach($json->type->geometry->coordinates[0] as $coordinates) 
    { 
        echo 'Set '.$set.': ';$set++; 
        echo $coordinates[0].','.$coordinates[1].'<br>'; 
    } 
    
    +0

    당신이 붙어있어, 당신이 일을 할 수있는 경우 : 'print_r' 구조체입니다. 2 : 점진적으로 'print_r'액세스. 이미 1 단계를 시도 했으므로'print_r ($ json);','print_r ($ json-> features)','print_r ($ json);'과 같이'print_r'에 각 레벨을 추가 할 수 있습니다. -> features [0]); '등 .. – FirstOne

    +0

    감사합니다. 다중 지오 펜스가있는 배열의 경우 특히 도움이되기를 바랍니다. –

    답변

    0

    단지에 foreach 루프를 변경합니다

    foreach($json->features[0]->geometry->coordinates[0] as $coordinates) 
    

    전체 작업 코드 :

    <?php 
    $str='{"type":"FeatureCollection","features":[{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[-77.0416259765625,38.89530825492018],[-77.03295707702638,38.89351294034218],[-77.03700184822084,38.89317057287496],[-77.0323669910431,38.892193563954955],[-77.04053163528442,38.89286160569515],[-77.0416259765625,38.89530825492018]]]}}]}'; 
    
    $json = json_decode($str); 
    // echo'<pre>';print_r($json);echo'</pre>'; 
    $set = 1; 
    foreach($json->features[0]->geometry->coordinates[0] as $coordinates) 
    { 
        echo 'Set '.$set.': ';$set++; 
        echo $coordinates[0].','.$coordinates[1]."<br>\n"; 
    } 
    
    // Output: 
    
    // Set 1: -77.041625976562,38.89530825492<br> 
    // Set 2: -77.032957077026,38.893512940342<br> 
    // Set 3: -77.037001848221,38.893170572875<br> 
    // Set 4: -77.032366991043,38.892193563955<br> 
    // Set 5: -77.040531635284,38.892861605695<br> 
    // Set 6: -77.041625976562,38.89530825492<br> 
    ?> 
    

     관련 문제

    • 관련 문제 없음^_^