我正在尝试在我的网站上实施谷歌地图标记。但它只显示蓝屏和标记。我无法在那里看到任何地图。请参阅下面的代码。我用mykey替换了apikey。
<?
define("MAPS_HOST", "maps.google.com");
define("KEY", "mykey"); // Place your API Key here...
// Get our address (from a database query or POST
$address = "india";
// Build our URL from the above...
$base_url = "http://" . MAPS_HOST . "/maps/geo?q=" . $address . "&output=csv" . "&key=" . KEY;
// Initalise CURL
$c = curl_init();
// Get the URL and save the Data
curl_setopt($c, CURLOPT_URL, $base_url);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
// Save location data
$csvPosition = trim(curl_exec($c));
// Close the connection
curl_close($c);
// Split pieces of data by the comma that separates them
list($httpcode,$elev, $lat, $long) = preg_split("/[,]+/", $csvPosition);
?>
<!DOCTYPE html>
<html>
<head>
<title>Geocoding Example - WinSysAdminBlog.com</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
#map_canvas { height: 512px; width: 512px; }
</style>
<script type="text/javascript"
src="http://maps.googleapis.com/maps/api/js?sensor=false">
</script>
<script type="text/javascript">
function initialize() {
var latlng = new google.maps.LatLng(<?php echo $lat; ?>, <?php echo $long; ?>);
var addressMarker = new google.maps.LatLng(<?php echo $lat; ?>, <?php echo $long; ?>);
var myOptions = {
zoom: 16,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
marker = new google.maps.Marker({ map:map, position: addressMarker });
}
</script>
</head>
<body onload="initialize()">
<h2>Geocoding Example</h2>
<div id="map_canvas"></div>
</body>
</html>
提前致谢。 此致 苏尼
答案 0 :(得分:1)
这只是猜测,但我会说有关您的地图请求的信息不正确,否则Google无法找到您要搜索的地址(这似乎不太可能)。尝试将完整格式的URL粘贴到浏览器中,并手动检查您要返回的CSV数据。
如果Google无法为您的地址提供地理编码,那么您将获得0,0作为纬度/经度,即非洲沿海多哥下方的海洋。可能会解释你所看到的蓝色方块。
答案 1 :(得分:0)