我从官方示例中复制了这段代码......我刚刚更换了api键和坐标。
我做错了什么?
地图显示OK ,,,但多边形不显示......
任何帮助都会被贬低......
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Maps JavaScript API v3 Example: Polygon Simple</title>
<link href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="//maps.googleapis.com/maps/api/js?key=AIzaSyAdL-4IAZxpfEjgVUHOTOHnPMAeD8KECNI&sensor=true"></script>
<script type="text/javascript">
function initialize() {
var myLatLng = new google.maps.LatLng(-34.921127, -57.952709);
var myOptions = {
zoom: 13,
center: myLatLng,
mapTypeId: google.maps.MapTypeId.TERRAIN
};
var bermudaTriangle;
var map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
var triangleCoords = [
new google.maps.LatLng(-57.980518,-34.922787),
new google.maps.LatLng(-57.953396,-34.942068),
new google.maps.LatLng(-57.953224,-34.942771),
new google.maps.LatLng(-57.928677,-34.920395),
new google.maps.LatLng(-57.955799,-34.900124)
];
// Construct the polygon
bermudaTriangle = new google.maps.Polygon({
paths: triangleCoords,
strokeColor: "#dddddd",
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: "#dddddd",
fillOpacity: 0.50
});
bermudaTriangle.setMap(map);
}
</script>
</head>
<body onload="initialize()">
<div id="map_canvas"></div>
答案 0 :(得分:0)
你的代码工作正常,但你的经纬度和经度混在一起。在设置视口时,您拥有我认为正确的顺序(以阿根廷拉普拉塔为中心),但在定义路径时,您可以切换订单。因此多边形被绘制在南大西洋的深处。