[英]Having trouble getting Google Maps to display on my site.
I'm getting my lat & long via: 我正在通过以下方式获取信息:
$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;
I return the correct lat & long. 我返回正确的纬度和经度。 So now I try to build my map: 因此,现在我尝试构建地图:
<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: HTML:
div id="map_canvas"></div>
Nothing is showing up. 什么都没有出现。 Am I missing something? 我想念什么吗?
Thanks. 谢谢。
您的< div id="map_canvas">
需要一个大小(宽度和高度),因此,
<div id="map_canvas" style="width:400px;height:300px"></div>
Add the following. 添加以下内容。 You need to use initialize()
in the onload function in the body as well 您还需要在主体的onload函数中使用initialize()
<body onload="initialize()">
<div id="map_canvas" style="width: 500px; height: 300px"></div>
</body>
Please refer to the google map playground examples 请参考谷歌地图游乐场示例
http://code.google.com/apis/ajax/playground/?exp=maps#map_simple http://code.google.com/apis/ajax/playground/?exp=maps#map_simple
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.