2011-09-21 3 views
3

Google지도에 여러 회사를 플로팅하고 이들을 지오 코딩해야한다는 것을 이해하고 싶습니다.Google지도로 주소를 위도/경도로 지오 코딩하는 방법

지도에 해당 플롯의 여러 마커 아래 코드가 있습니다.

어떻게하면 여러 회사 주소 (첫 번째 예제로 다음 주소 사용)를 지오 코딩하고 내가 가지고있는 현재 코드에 통합 할 수 있습니까?

Google 문서를 이해할 수없고 이미 갖고있는 문서와 통합 할 수 없으므로 누군가의 도움이 필요합니다.

답변

8

당신은

편집을 게시물 코드의 좌표를 얻기 위해 google's geocoding을 사용할 수 있습니다 : 나는 당신이 그러나 확인과 같은 질문의 의미를 변경하는 등 정말하지 않습니다. 시험해 보시기 바랍니다. :

// Creating an array that will contain the coordinates 
// for New York, San Francisco, and Seattle 
var places = []; 

// Adding a LatLng object for each city 
//places.push(new google.maps.LatLng(40.756, -73.986)); 
//places.push(new google.maps.LatLng(37.775, -122.419)); 
//places.push(new google.maps.LatLng(47.620, -122.347)); 
//places.push(new google.maps.LatLng(-22.933, -43.184)); 
var result; 
var xmlhttp = new XMLHttpRequest(); 
xmlhttp.open("GET", "http://maps.googleapis.com/maps/api/geocode/json?address=your+code&sensor=false",true); 
xmlhttp.onreadystatechange=function() { 
    if (xmlhttp.readyState==4) { 
     result = eval('(' + xmlhttp.responseText + ')'); 
if (result.status == "OK") { 
var location = new google.maps.LatLng(result.results[0].geometry.location.lat, result.results[0].geometry.location.lng); 
places.push(location); 

가능한 작은 오류가 있음에도 불구하고이 방법을 사용해보십시오.

EDIT2 : 나는 지금 simpler solution을 발견했다 :

// Creating an array that will contain the coordinates 
// for New York, San Francisco, and Seattle 
var places = []; 

// Adding a LatLng object for each city 
//places.push(new google.maps.LatLng(40.756, -73.986)); 
//places.push(new google.maps.LatLng(37.775, -122.419)); 
//places.push(new google.maps.LatLng(47.620, -122.347)); 
//places.push(new google.maps.LatLng(-22.933, -43.184)); 
var geocoder = new google.maps.Geocoder(); 
geocoder.geocode({ 'address': "your+code"}, function(results, status) { 
    if (status == google.maps.GeocoderStatus.OK) { 
    map.setCenter(results[0].geometry.location); 
    //var marker = new google.maps.Marker({ 
     //map: map, 
     //position: results[0].geometry.location 
    //}); 
    places.push(results[0].geometry.location); 
    } else { 
    alert("Geocode was not successful for the following reason: " + status); 
    } 
}); 
+0

감사합니다, 나는 홀로 내가 가지고있는 현재의 코드와 병합 시작하는 위치의 아무 생각도 없어. – Rob

+1

내가 제공 한 사이트를 살펴보고 : http://www.w3schools.com/xml/xml_http.asp 과 같이 요청을 작성하십시오. http://maps.googleapis.com/maps/api/geocode/json? address = SW1A + 0AA Google의 eval json 응답 및 – slawekwin

+1

센서가 지오 코드 요청에서 잊어 버렸습니다. maps.googleapis.com/maps/api/geocode/json?address=SW1A+0AA&sensor = false – slawekwin

관련 문제