2011-08-26 9 views
7

도시 및 반지름이 지정된 경우 도시 인을 반환하는 Java 응용 프로그램을 작성하려고합니다. Google Maps API를 사용하여이 작업을 수행 할 수 있다고 생각했지만 Places API에 대한 행운을 얻지는 못했습니다. 관심 장소 (예 : 레스토랑)를 반환합니다. Google API를 사용하여이를 수행하는 방법이 있습니까? 아니면 권장 할만한 다른 API (또는이 방법)가 있습니까?Google Places API를 사용하여 특정 도시의 인근 도시 가져 오기

답변

2

Places API를 사용하고 싶지 않을 가능성이 큽니다. 지오 코딩/역 지오 코딩을 사용하여 원하는 것을 얻는 방법이 있는지 알아볼 수 있습니다. http://code.google.com/apis/maps/documentation/geocoding/을 참조하십시오.

성능 및 정확도 요구 사항에 따라 Google Maps API (또는 다른 무료 도구)를 사용하여 쉽게 (전 세계적으로) 쉽게 수행 할 수 없을 수도 있지만, 특히 일을 단순화 할 수있는 지리적 제한이있는 경우 (예 : 미국 만).

3

난 당신도 요청을 할 수 당신이 및 GeoNames.org API (A file_get_contents 외에 Google지도 지오 코딩 API를 결합하여 주변의 모든 도시를 검색 할 수있는 코드를 작성했습니다). 은 API의이 API의 방문에 대한 자세한 내용은

을 제한하고 있기 때문에

/* 
* Get cities based on city name and radius in KM 
*/ 

// get geocode object as array from The Google Maps Geocoding API 
$geocodeObject = json_decode(file_get_contents('https://maps.googleapis.com/maps/api/geocode/json?address={CITY NAME},{COUNTRY CODE}'), true); 

// get latitude and longitude from geocode object 
$latitude = $geocodeObject['results'][0]['geometry']['location']['lat']; 
$longitude = $geocodeObject['results'][0]['geometry']['location']['lng']; 

// set request options 
$responseStyle = 'short'; // the length of the response 
$citySize = 'cities15000'; // the minimal number of citizens a city must have 
$radius = 30; // the radius in KM 
$maxRows = 30; // the maximum number of rows to retrieve 
$username = '{YOUR USERNAME}'; // the username of your GeoNames account 

// get nearby cities based on range as array from The GeoNames API 
$nearbyCities = json_decode(file_get_contents('http://api.geonames.org/findNearbyPlaceNameJSON?lat='.$latitude.'&lng='.$longitude.'&style='.$responseStyle.'&cities='.$citySize.'&radius='.$radius.'&maxRows='.$maxRows.'&username='.$username, true)); 

// foreach nearby city get city details 
foreach($nearbyCities->geonames as $cityDetails) 
{ 
    // do something per nearby city 
} 

귀하의 요청 량에주의 하시고 다음 URL의 :

+1

이 질문이 중복 된 것으로 판단되면 바로 신고하십시오. 답변으로 다른 Stack Overflow 게시물에 대한 링크를 게시하지 마십시오. – JAL

+0

알겠습니다, 잘 알고 있습니다! 사방에 내 답변을 게시하면 중복 답변으로 표시 될 수 있다고 생각했습니다 ... 답변을 수정하고 다른 게시물에 링크하지 마십시오 √ – 0x1ad2

관련 문제