As I was working on a code to extract data from a CSV file using a split function as the separator, and then calculate the distance between two sets of input coordinates, I encountered an error message stating "a.lat is not a function." Despite searching online for solutions to this specific error, I have been unable to find a resolution. Can anyone offer assistance in resolving this issue?
Here is an example of the coordinates I am working with:
-6.168454914420734, 106.7574467
-6.16897225004169, 106.7570443
Below is the code snippet that I am currently using:
<!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>