2
我創建的代碼可以通過使用分隔符作爲分隔符來協調CSV文件中的數據,並計算兩個輸入座標之間的距離。但結果總是顯示錯誤a.lat不是函數。我已經在網上衝浪有關這種特定的錯誤類型,似乎無法找到正確的解決方案,任何人都可以請幫我解決這個錯誤。Google Maps API a.lat不是函數錯誤
這裏是我的座標例如:
-6.168454914420734, 106.7574467
-6.16897225004169, 106.7570443
這裏是我的代碼:
<!DOCTYPE html>
<html>
<head>
<script src="http://maps.googleapis.com/maps/api/js"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&libraries=geometry"></script>
<script>
function calcDistance(p1, p2){
return (google.maps.geometry.spherical.computeDistanceBetween(p1, p2)/1000).toFixed(2);
}
function encodeLatLngPolygon(array) {
var polyOptions = {
strokeColor: '#000000',
strokeOpacity: 1.0,
strokeWeight: 3
}
poly = new google.maps.Polyline(polyOptions);
var path = poly.getPath();
for(var i=0;i<array.length;i++) {
var xyz = new google.maps.LatLng(parseFloat(array[i][0]).toFixed(2), parseFloat(array[i][1]).toFixed(2));
path.push(xyz);
}
var code = google.maps.geometry.encoding.encodePath(path)
return code;
}
function readTextFile(file)
{
var rawFile = new XMLHttpRequest();
rawFile.open("GET", file, true);
rawFile.onreadystatechange = function()
{
if(rawFile.readyState === 4)
{
if(rawFile.status === 200 || rawFile.status == 0)
{
var allText = rawFile.responseText;
var byline = allText.split('\n');
for(var e=0;e<4;e++){
var coor=byline[e].split(',');
alert(calcDistance(coor[0],coor[1]));
}
}
}
}
rawFile.send(null);
}
function initialize() {
var mapProp = {
center:new google.maps.LatLng(51.508742,-0.120850),
zoom:5,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
var map=new google.maps.Map(document.getElementById("googleMap"),mapProp);
readTextFile("DaerahG.csv");
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<title>kenny</title>
</head>
<body>
<div id="googleMap" style="width:1000px;height:700px; float:left;"></div>
</body>
</html>
謝謝,它實際上確實很好。 – Kenken
如果這回答了你的問題,請[接受它](http://meta.stackoverflow.com/questions/5234/how-does-accepting-an-answer-work) – geocodezip