我正在使用谷歌地图,我正在尝试在地图上创建一个多边形,但由于某种原因,谷歌只是给了我没有多边形的地图
代码:
<script type="text/javascript">
var map;
var infoWindow;
var sandCoodrs;
function initialize() {
var myLatLng = new google.maps.LatLng(-26, 28);
var mapOptions = {
zoom: 10,
center: myLatLng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"),
mapOptions);
var sandtonCoords = [];
//出于某种原因,在这一点之后firebug没有进入代码并且sandtonCoords保持为空,因此没有多边形
jQuery.get('http://localhost/magnetic/Main.txt', function(data)
{
var StringData = data;
StringData.trim();
var MainArray = data.split(",");
var length = MainArray.length;
for(k=0;k<length;k++)
{
var StringCoords = MainArray[k];
var LatLongArray = StringCoords.split(" ");
var Lat = parseFloat(LatLongArray[0]);
Lat.trim();
var Long = parseFloat(LatLongArray[1]);
Long.trim();
sandtonCoords.push(new google.maps.LatLng(Lat,Long));
}
});
andton = new google.maps.Polygon({
paths: sandtonCoords,
strokeColor: "#FF0000",
strokeOpacity: 0.8,
strokeWeight: 3,
fillColor: "#FF0000",
fillOpacity: 0.35
});
sandton.setMap(map);
// Add a listener for the click event
google.maps.event.addListener(sandton, 'click', showArrays);
infowindow = new google.maps.InfoWindow();
}`