-3
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Simple Polygon</title>
<style>
html, body {
height: 100%;
margin: 0;
padding: 0;
}
#map {
height: 100%;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
// This example creates a simple polygon representing the Bermuda Triangle.
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 12,
center: {lat: 33.53625, lng: -111.92674},
mapTypeId: google.maps.MapTypeId.TERRAIN
});
// Define the LatLng coordinates for the polygon's path.
var triangleCoords = [
{lat: 33.53625, lng: -111.92674},
{lat: 33.51049, lng: -111.96279},
{lat: 33.50161, lng: -111.90374}
];
// Construct the polygon.
var bermudaTriangle = new google.maps.Polygon({
paths: triangleCoords,
strokeColor: '#FF0000',
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: '#FF0000',
fillOpacity: 0.35
});
bermudaTriangle.setMap(map);
}
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?signed_in=true&callback=initMap"></script>
</body>
</html>
上面的程序是由谷歌地图API一个JavaScript + HTML程序,我试图取代如何将字符串分配给单个字符?
// Define the LatLng coordinates for the polygon's path.
var triangleCoords = [
{lat: 33.53625, lng: -111.92674},
{lat: 33.51049, lng: -111.96279},
{lat: 33.50161, lng: -111.90374}
];
与
var g= "{lat:33.53625 , lng: -111.92674},";
// Define the LatLng coordinates for the polygon's path.
var triangleCoords = [
g
{lat: 33.51049, lng: -111.96279},
{lat: 33.50161, lng: -111.90374}
];
,但它不工作,任何想法如何使它工作吗?我所要做的只是将坐标值分配给单个字符,然后在程序中使用它们来构建多边形。
你忘了'''在后g',让你有一个语法错误杀死整个脚本块。 –
对不起,我试了他们两个,但他们没有工作。 – pra
感谢blex和marc b,我删除了var g =“...”中的引号,并在g后添加了逗号,它的工作方式非常魅力 – pra