0

我正在尝试在我的网站中实现谷歌地图标记。但它只显示一个蓝屏和一个标记。我在那里看不到任何地图。请在下面查看我的代码。我已经用 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>

提前致谢。真诚的,苏尼尔

4

2 回答 2

1

这只是一个猜测,但我会说您的地图请求格式不正确,否则 Google 无法找到您正在搜索的地址(这似乎不太可能)。尝试将格式完整的 URL 粘贴到浏览器中,然后手动检查您返回的 CSV 数据。

如果 Google 无法为您的地址提供地理编码,您将返回 0, 0 作为纬度/经度,即非洲海岸多哥下方的海洋。可能会解释你看到的蓝色方块。

于 2013-04-12T03:26:36.973 回答
0

看起来您正在尝试使用已弃用的 v2 geocoder。请改用v3 地理编码服务

已报告 API 的 v2 版本存在问题

于 2013-04-12T03:49:09.267 回答