2012-04-23 4 views
2

난 내가 여기서 무엇을 원하는 내 HTML에서이 자바 스크립트지도 표현이구글의 API를 V3를 사용하여 주소에서 위치를 얻으려고 노력

<script type="text/javascript"> 
var geocoder; 
var map; 
function getmaploc() { 
    geocoder = new google.maps.Geocoder(); 
    var myOptions = { 
     zoom: 8, 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
    }; 
    geocoder.geocode('cairo', 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 
      }); 
     } else { 
      alert("Geocode was not successful for the following reason: " + status); 
     } 
     map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); 
    }); 
} 
</script> 

<body onload="getmaploc()"> 
    <div id="map_canvas" style="width: 320px; height: 480px;"></div> 
</body> 

내가이와 무슨 잘못 파악하지 못할 위치를 부여받을 것입니다해야 어떤 도움 ??

+0

형식을 지정하십시오. 많은 사람들이 포함되어 있습니다. 형식이 올바르지 않은 코드는 읽지 않습니다. –

+0

미안 해요. stackoverflow에 새롭게 추가되었습니다. –

+0

서식을 다시 지정하면 수정 내용이 여전히 읽기 어려워졌습니다. 다른 팁이 있습니다 : "작동하지 않습니다"라는 오류 메시지가 없으면 다른 사람들이 도움을 받기가 더 어려워집니다. –

답변

4

  • 먼저지도
  • 지오를()가 초기화 생략 중괄호 인수로 GeocoderRequest 오브젝트 기대 여러 오류가

고정 코드 :

var geocoder; 
var map; 
function getmaploc() { 
    geocoder = new google.maps.Geocoder(); 
    var myOptions = { 
     zoom : 8, 
     mapTypeId : google.maps.MapTypeId.ROADMAP 
    }; 
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); 

    geocoder.geocode({ 
     address : 'cairo' 
    }, function(results, status) { 
     console.log(results); 
     if(status == google.maps.GeocoderStatus.OK) { 
      map.setCenter(results[0].geometry.location); 
      new google.maps.Marker({ 
       map : map, 
       position : results[0].geometry.location 
      }); 
     } else { 
      alert("Geocode was not successful for the following reason: " + status); 
     } 

    }); 
} 
+0

+1 및 다시 포맷팅 문제가 해결되었습니다! lol –

+1

제 들여 쓰기에 대해 불평하지 마십시오. ^^ –

+0

감사합니다. 문제가 해결되었습니다. Dr.Molle –

관련 문제