2011-09-21 15 views
3

Googleマップで複数の企業をプロットし、これらをジオコードする必要があることを理解したいと考えています。Googleマップを使用して緯度/経度に住所をジオコードする方法

マップ上にそのプロットの複数のマーカーの下にコードがあります。

いくつかの会社の住所を(最初の例として次の住所を使用して)ジオコードし、それを現在のコードに組み込むにはどうすればよいですか?

Googleのドキュメントを理解できず、すでに持っているものと組み合わすことができないので、本当に誰かの助けが必要です。

答えて

8

あなたのポストコード

EDITの座標を取得するためにgoogle's geocodingを使用することができます。私は本当にあなたがそれますが、OKのような質問の意味を変える好きではありません。このような(テストされていない)そのようなsthを試してください:

// 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

関連する問題