-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