2012-03-22 6 views
1

나는 PHP에서 이것을하는 방법을 모른다. openstreetmap.org에서 지오 코드 데이터를 가져 오려고하지만 PHP에서이 작업을 수행해야합니다.url in php에서 질문하기

자바 스크립트에서

(그리고 나는이 작업을), 그건 :

<script type="text/javascript" 
    src="http://nominatim.openstreetmap.org/reverse?format=xml&lat=43.642018&lon=-79.374671"> 
</script> 

는 그 URL을 가지고 있지만 PHP에서 그것을 실행하는 방법을 모르겠어요.

<?php 
    $url = "http://nominatim.openstreetmap.org/reverse?format=xml&lat=43.642018&lon=-79.374671"; 
    $response = file_get_contents($url); 
?> 

하지만이 작동하지 않습니다

이 나는 ​​노력했다. 나는 곱슬 곱슬로 똑같이 시도했다. 모든 아이디어 또는 PHP에서 불가능한이 유형의 쿼리입니까?

+0

오류가 있습니까? 대부분의 서버에서는'/ var/log/httpd/error_log'에 있습니다. – JKirchartz

+0

첫 번째 버전에는 OpenStreetMap의 자바 스크립트가 포함되어 있지만 두 번째 버전에서는 무엇을하려고합니까? 제 생각에는 "지오 코드 데이터 가져 오기"보다 좀 더 구체화되어야한다고 생각합니다. –

+0

URL이 나를 위해 반환하는 모든 것은 ' 지오 코드를 사용할 수 없음' –

답변

2

사용이 필요한 경우 ;

$xml = simplexml_load_file("http://nominatim.openstreetmap.org/reverse?format=xml&lat=43.642018&lon=-79.374671"); 
print_r($xml); 

값 배열을 반환합니다 (아래 참조).

SimpleXMLElement Object 
(
    [@attributes] => Array 
     (
      [timestamp] => Thu, 22 Mar 12 18:31:11 +0000 
      [attribution] => Data Copyright OpenStreetMap Contributors, Some Rights Reserved. CC-BY-SA 2.0. 
      [querystring] => format=xml&lat=43.642018&lon=-79.374671 
     ) 

[result] => 1, Yonge Street, Corktown, Toronto, Ontario, M5B2H1, Canada 
[addressparts] => SimpleXMLElement Object 
    (
     [house_number] => 1 
     [road] => Yonge Street 
     [suburb] => Corktown 
     [city] => Toronto 
     [county] => Toronto 
     [state] => Ontario 
     [postcode] => M5B2H1 
     [country] => Canada 
     [country_code] => ca 
    ) 

) 

그런 다음 적합하다고 생각되는 데이터를 조작하십시오.

+0

이것은 해결책이었습니다. 감사! – Raymond

1

그것은 단지 특정에 대한 주소가 있다는 것을 의미

<?xml version="1.0" encoding="UTF-8" ?> 
<reversegeocode timestamp='Thu, 22 Mar 12 18:07:13 +0000' attribution='Data Copyright OpenStreetMap Contributors, Some Rights Reserved. CC-BY-SA 2.0.' querystring='format=xml&amp;lat=100&amp;Lon=100'> 
<error>Unable to geocode</error></reversegeocode> 

을 반환하지 좌표 ..이 그러나이 http://nominatim.openstreetmap.org/reverse?format=xml&lat=52.5487429714954&lon=100

읽기 API 당신은 자세한 내용

+1

죄송합니다. 본인이 처음에 지정한 위도와 경도가 예제였습니다. 나는 위도와 경도가 유효하다는 질문을 수정했다. 내 $ 응답이 null 인 것 같습니다. – Raymond

+0

저에게 맞습니다. 토론토 정보를 보여줍니다. DNS에 문제가 있거나 공유 호스팅을 사용중인 경우 서버에서 금지되어 있습니다. –