Google지도 API 및 PHP로 리버스 지오 코딩을하여 LAT, 긴 좌표를 사용하여 가장 가까운 위치를 얻으십시오.

StackOverflow https://stackoverflow.com/questions/2054635

문제

Google Map API 리버스 지오 코딩 및 PHP를 사용하여 좌표 (LAT, Long)에서 가장 가까운 주소 또는 도시를 얻으려면 기능이 필요합니다 ... 일부 샘플 코드를 제공하십시오.

도움이 되었습니까?

해결책

당신은 그것을 사용해야합니다 GetLocations 방법에 대한 방법 Gclientgeocoder 객체 Google 매핑 API

var point = new GLatLng (43,-75);
var geocoder = new GClientGeocoder();
geocoder.getLocations (point, function(result) {
    // access the address from the placemarks object
    alert (result.address);
    });

편집하다: 확인. 당신은이 일을 서버 측면에하고 있습니다. 이것은 당신이 그것을 사용해야한다는 것을 의미합니다 HTTP 지오 코딩 서비스. 이를 위해서는 링크 된 기사에 설명 된 URL 형식을 사용하여 HTTP 요청을해야합니다. HTTP 응답을 구문 분석하고 주소를 꺼낼 수 있습니다.

// set your API key here
$api_key = "";
// format this string with the appropriate latitude longitude
$url = 'http://maps.google.com/maps/geo?q=40.714224,-73.961452&output=json&sensor=true_or_false&key=' . $api_key;
// make the HTTP request
$data = @file_get_contents($url);
// parse the json response
$jsondata = json_decode($data,true);
// if we get a placemark array and the status was good, get the addres
if(is_array($jsondata )&& $jsondata ['Status']['code']==200)
{
      $addr = $jsondata ['Placemark'][0]['address'];
}

NB 그만큼 Google은 서비스 약관을지도합니다 Google지도에 결과를 넣지 않고 지오 코딩 데이터는 금지되어 있다고 명시 적으로 명시하고 있습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top