2017-11-03 15 views
0

오버 패스 터보를 사용하여지도에 정보를 표시하고 있습니다. 다음과 같이 (var_dump 쇼 것입니다) JSON 형식으로PHP의 오버 패스 API 및 json 출력

//overpass query 
$overpass = 'http://overpass-api.de/api/interpreter?data=[out:json];area(3600046663)->.searchArea;(node["amenity"="drinking_water"](area.searchArea););out;'; 
// collecting results in JSON format 
$html = file_get_contents($overpass); 
$jsonout = json_decode($html); 
// this line just checks what the query would give as output 
var_dump($jsonout); 

쿼리 결과 : 등등

version: 0.6 
generator: "Overpass API" 
osm3s: 
timestamp_osm_base: "2017-11-03T06:25:02Z" 
timestamp_areas_base: "2017-11-03T05:45:02Z" 
copyright: "The data included in this document is from www.openstreetmap.org. The data is made available under ODbL." 
elements: 
0: 
type: "node" 
id: 254917402 
lat: 46.0672187 
lon: 11.1379545 
tags: 
amenity: "drinking_water" 
1: 
type: "node" 
id: 257481472 
lat: 46.0687113 
lon: 11.1201097 
tags: 
amenity: "drinking_water" 

하고 다음과 같이 내 코드 (내가 PHP를 사용)의 부분이다.

당신은 스스로를 볼 수 있습니다, 복사/브라우저에서 쿼리 URL 붙여 넣기 : http://overpass-api.de/api/interpreter?data=[out:json];area(3600046663)-%3E.searchArea;(node[%22amenity%22=%22drinking_water%22](area.searchArea););out;

당신이 볼 수 있듯이, 배열 위 위도경도 정보를 가지고 각 element을. 지도에 마커를 보여줄 사람이 필요합니다.

배열에서 각 요소latlon 정보를 분리 할 수 ​​없습니다. 어떻게해야합니까? 여기

답변

3

당신은 갈 :

<?php 

// overpass query 
$overpass = 'http://overpass-api.de/api/interpreter?data=[out:json];area(3600046663)->.searchArea;(node["amenity"="drinking_water"](area.searchArea););out;'; 

// collecting results in JSON format 
$html = file_get_contents($overpass); 
$result = json_decode($html, true); // "true" to get PHP array instead of an object 

// elements key contains the array of all required elements 
$data = $result['elements']; 

foreach($data as $key => $row) { 

    // latitude 
    $lat = $row['lat']; 

    // longitude 
    $lng = $row['lon']; 
} 

?>