我在谷歌地图上做了一个简单的页面,显示了一堆指针。 当我在我的电脑上试用这个代码时,它没有任何问题。
但是,当我在服务器上传文件时,谷歌地图不会出现,我收到以下错误:
SyntaxError: invalid property id variables.js:1
SyntaxError: missing ; before statement fonctions.js:1
SyntaxError: missing ; before statement villes.js:1
ReferenceError: initialisation is not defined index.html:1
知道我本可以做错什么吗? 在此先感谢:)
我的代码:
索引.html
<head>
<link rel="stylesheet" href="style.css" />
<title>Les dés de Monique</title>
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false" ></script>
<script type="text/javascript" src="./initialisation.js"></script>
<script type="text/javascript" src="./variables.js"></script>
<script type="text/javascript" src="./fonctions.js"></script>
<script type="text/javascript" src="./villes.js"></script>
</head>
<body onload="initialisation()">
<div id="panel">
<input id="address" type="textbox" value="Bains de Bretagne, France">
<input type="button" value="Ajouter" onclick="coderadresse()">
</div>
<div id="map_canvas" style="width: 100%; height: 100%;"></div>
</body>
</html>
变量.js
var geocoder = new google.maps.Geocoder();
var map;
var latlng = new google.maps.LatLng(46.1100, 2.1939);
var bounds;
var myOptions =
{
//Controles de l'utilisateur
keyboardShorcuts: true,
draggable: true,
scrollwheel: true,
disableDoubleClickZoom: true,
disableDefaultUI:true,
//Affichage (ou non) des boutons
navigationControl: true,
mapTypeControl: true,
zoomControl: true,
panControl: true,
overviewMapControl: false,
rotateControl: false,
scaleControl: false,
streetViewControl: false,
center: latlng,
mapTypeId: google.maps.MapTypeId.TERRAIN
};
var styles =
[
{
featureType: "localities",
elementType: "labels",
stylers:
[
{
visibility: "off"
}
]
},
{
featureType: "road",
stylers:
[
{
visibility: "off"
}
]
}
];
villes .js
var villes =
[
"Tirana",
"Berlin",
"Andorre-la-Vieille",
"Vienne",
"Bruxelles",
"Minsk",
"Sarajevo",
"Sofia",
"Nicosie",
"Zagreb",
"Copenhague",
"Madrid",
"Tallinn",
"Helsinki",
"Paris",
"Athènes",
"Budapest",
"Dublin",
"Reykjavik",
"Rome",
"Riga",
"Vaduz",
"Vilnius",
"Luxembourg",
"Skopje",
"La Valette",
"Chisinau",
"Monaco",
"Podgorica",
"Oslo",
"Amsterdam",
"Varsovie",
"Lisbonne",
"Prague",
"Bucarest",
"Londres",
"Moscou",
"Belgrade",
"Bratislava",
"Ljubljana",
"Stockholm",
"Berne",
"Kiev",
]
var coordonneesvilles =
[
new google.maps.LatLng(41.33165, 19.83179999999993),
new google.maps.LatLng(52.519171, 13.406091199999992),
new google.maps.LatLng(42.50631740000001, 1.521835499999952),
new google.maps.LatLng(48.2081743, 16.37381890000006),
new google.maps.LatLng(50.8503396, 4.351710300000036),
new google.maps.LatLng(53.9, 27.56666670000004),
new google.maps.LatLng(43.8562586, 18.413076300000057),
new google.maps.LatLng(42.6978388, 23.32166970000003),
new google.maps.LatLng(35.1666667, 33.366666699999996),
new google.maps.LatLng(45.8130293, 15.977894900000024),
new google.maps.LatLng(55.6760968, 12.568337100000008),
new google.maps.LatLng(40.4167754, -3.7037901999999576),
new google.maps.LatLng(59.43696079999999, 24.75357459999998),
new google.maps.LatLng(60.17332440000001, 24.941024800000037),
new google.maps.LatLng(48.856614, 2.3522219000000177),
new google.maps.LatLng(37.9837155, 23.72930969999993),
new google.maps.LatLng(47.497912, 19.04023499999994),
new google.maps.LatLng(53.3498053, -6.260309699999993),
new google.maps.LatLng(64.13533799999999, -21.89521000000002),
new google.maps.LatLng(41.8929163, 12.482519899999943),
new google.maps.LatLng(56.9496487, 24.10518639999998),
new google.maps.LatLng(47.14136999999999, 9.520700000000033),
new google.maps.LatLng(54.6871555, 25.279651400000034),
new google.maps.LatLng(49.815273, 6.129583000000025),
new google.maps.LatLng(41.9973462, 21.42799560000003),
new google.maps.LatLng(35.89779, 14.51410599999997),
new google.maps.LatLng(47.02685899999999, 28.84155099999998),
new google.maps.LatLng(43.73841760000001, 7.42461579999997),
new google.maps.LatLng(42.442575, 19.26864599999999),
new google.maps.LatLng(59.9138688, 10.752245399999993),
new google.maps.LatLng(52.3702157, 4.895167899999933),
new google.maps.LatLng(52.2296756, 21.012228700000037),
new google.maps.LatLng(38.7252993, -9.150036399999976),
new google.maps.LatLng(50.0755381, 14.43780049999998),
new google.maps.LatLng(44.4325, 26.103888900000015),
new google.maps.LatLng(51.51121389999999, -0.11982439999997041),
new google.maps.LatLng(55.7512419, 37.6184217),
new google.maps.LatLng(44.8205556, 20.462222200000042),
new google.maps.LatLng(48.1458923, 17.107137299999977),
new google.maps.LatLng(46.05645089999999, 14.50807020000002),
new google.maps.LatLng(59.32893000000001, 18.064910000000054),
new google.maps.LatLng(46.9479222, 7.444608499999958),
new google.maps.LatLng(50.4501, 30.523400000000038),
]
初始化.js
//Fonction d'initialisation de la carte, selon des valeurs précisées
function initialisation()
{
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
centrercarte();
placermarqueurs();
}
fonctions .js
function centrercarte()
{
bounds = new google.maps.LatLngBounds();
for (var i = 0 ; i < coordonneesvilles.length ; i++)
{
bounds.extend(coordonneesvilles[i]);
}
map.fitBounds(bounds);
}
function placermarqueurs()
{
for (var i = 0 ; i < coordonneesvilles.length ; i++)
{
var optionsmarqueur =
{
position: coordonneesvilles[i],
map: map,
draggable: false,
clickable:false,
title:villes[i],
}
var marqueurville = new google.maps.Marker(optionsmarqueur);
}
}
function coderadresse()
{
var address = document.getElementById('address').value;
geocoder.geocode( { 'address': address}, function(results, status)
{
if (status == google.maps.GeocoderStatus.OK)
{
//Cette partie là devient inutile si on rafraichit la carte par redirections successives.
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker(
{
map: map,
position: results[0].geometry.location
});
envoyerdonnees(address, results[0].geometry.location);
}
else
{
alert('Désolé, le géocodage a échoué... ( ' + status + ')');
}
});
}
function envoyerdonnees(nom, coordonnees)
{
nom = ("\""+nom+"\", \n");
coordonnees = ("new google.maps.LatLng"+coordonnees+", \n");
//redirection vers la fonction de traitement de fichier
document.location.href=("./traitementfichier.php?nom="+nom+"&coordonnees="+coordonnees);
}
答案 0 :(得分:0)
检查FTP-Upload是否具有正确的设置。也许你上传的文件是&#34;二进制&#34;模式而不是&#34; ascii&#34;模式。
答案 1 :(得分:0)
另一个建议:身体&#34; onload&#34;很不确定,因为代码将在解析器执行时执行这行代码。所以如果你参考&#34; map_canvas&#34;操作可能会失败。在您的PC上,源代码以毫秒为单位加载 - 所以这并不会造成伤害,但是从您的服务器(取决于您的互联网速度),此下载可能需要很长时间。
尝试使用以下行实现jQuery:
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
然后使用:
<script language="javascript">
$(document).ready(function() {
initialisation()
});
</script>