2012-08-16 68 views
0

我得到我的经纬度&长通:无法让Google地图显示在我的网站上。

$geocode = file_get_contents('http://maps.google.com/maps/api/geocode/json?address=' . $g_location . '&sensor=true'); 
$output= json_decode($geocode); 

$lat = $output->results[0]->geometry->location->lat; 
$long = $output->results[0]->geometry->location->lng; 

我返回正确的纬度&长。所以,现在我尝试建立我的地图:

<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCTQqh2ksk9ZTqSfx-_ki_lHj-q32kYIY8&sensor=false"> </script> 
<script language="JavaScript"> 
var map; 
     function initialize() { 
     var mapOptions = { 
      zoom: 8, 
      center: new google.maps.LatLng(<?=$lat?>, <?=$long?>), 
      mapTypeId: google.maps.MapTypeId.ROADMAP 
     }; 
     map = new google.maps.Map(document.getElementById('map_canvas'), 
      mapOptions); 
     } 

     google.maps.event.addDomListener(window, 'load', initialize);  
</script> 

HTML:

div id="map_canvas"></div> 

没有被显示出来。我错过了什么吗?

谢谢。

回答

1

你< div id="map_canvas">需要一个尺寸(宽,高),因此,

<div id="map_canvas" style="width:400px;height:300px"></div> 
相关问题