遇到了一个错误,找了好几天,都不知道咋解决 Invalid or unexpected token 提示在js的第一句有错误,但是第一句没错呀,
这是js文件
window.onload=getMyLo[/color]cation;
function getMyLocation (){
if (navigator.geolocation)navigator.geolocation.getCurrentPosition(displayLocation,displayError);//displayLocation和displayError都是函数,因为函数也是一个值
else alert("Oops,no geolocation supprot");
}
function displayLocation(position){
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
var div= document.getElementById("location");
div.innerHTML="you are at Latitude:"+latitude+","+"Longitude:" +longitude;
}
function displayError(error){
var errorTypes={
0:"unknow error",
1:"Permission denied by user",
2:"Position is not available",
3:"Request timed out"};
var errorMessage =errorType[error.code];//使用error.code属性}
if(error.code==0||error.code==2){
errorMessage=errorMessage+" "+error.message;//对于错误0和2,有时error.message有额外的信息
}
var div=document.getEelementById("location");
div.innerHTML=errorMessage;
}/*地理定位会给处理程序传入一个error对象,error对象有一个code属性,其中包含1到3的一个数,多以现在要做的事情是把错误类型和错误消息关联起来*/
这是html文件
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Where am I?</title>
<script src="myLoc.js"></script>
</head>
<body>
<div id="Location">Your Location will go here.</div>
</body>
</html>