0

I am trying to read in lines from a text file that are in this form; 34.925,150.977 35.012,151.034 34.887,150.905

I am currently trying to use this methodology, which obviously isn't working. Any help would be appreciated.

var ltlng = [];
var txtFile = new XMLHttpRequest();
    txtFile.open("GET", "C:\Gmap\LatLong\Coordinates.txt", true);
    txtFile.onreadystatechange = function() {
        if (txtFile.readyState === 4) {  
        if (txtFile.status === 200) {  // Makes sure it's found the file.
           lines = txtFile.responseText.split("\n"); // separate each line into an array
             ltlng.push(new google.maps.LatLng(lines.split(",")[0],lines.split(",")[1]); //create the marker icons latlong array
            }
        }
    }
4

1 回答 1

0

XMLHttpRequest当资源由HTTP/S协议(而不是file协议,如您的示例)调用时有效

因此,要使您的代码正常工作,您应该尝试使用此代码和 Web 服务器

于 2012-04-18T09:56:18.487 回答