2014-12-04 107 views
0

我試圖修改谷歌商店定位器的例子,可以在這裏找到: https://googlemaps.github.io/js-store-locator/examples/panel.html。 但無論我嘗試它似乎它不能解析CSV。 我已閱讀這個問題Google Maps Store Locator - modify default example,但我的CSV根本沒有修改。我甚至沒有打開它,編輯它。只是爲了清楚我沒有修改 - 更改示例的任何文件,我只是想看看它是如何工作的。可能是我的問題?到目前爲止,我曾嘗試:谷歌地圖商店定位器不解析CSV

  • 下載解壓並運行panel.html
  • 下載解壓不
  • 下載到不同的PC上運行(不Excel中安裝)
  • 從XAMPP
  • 上傳到它運行一個web服務器

我還能試試什麼?我真的需要它的工作,所以我可以修改它,並在其上構建我的項目的一部分。 在此先感謝

回答

0

這是代碼示例(從此blog)應該給你一個指導。由於你沒有發佈你的代碼片段,所以很難說出它究竟有什麼問題。

或者,您可以嘗試使用此library。無論哪個幫助。

<script type="text/javascript"> 
 
    // ref: http://stackoverflow.com/a/1293163/2343 
 
    // This will parse a delimited string into an array of 
 
    // arrays. The default delimiter is the comma, but this 
 
    // can be overriden in the second argument. 
 
    function CSVToArray(strData, strDelimiter){ 
 
     // Check to see if the delimiter is defined. If not, 
 
     // then default to comma. 
 
     strDelimiter = (strDelimiter || ","); 
 

 
     // Create a regular expression to parse the CSV values. 
 
     var objPattern = new RegExp(
 
      (
 
       // Delimiters. 
 
       "(\\" + strDelimiter + "|\\r?\\n|\\r|^)" + 
 

 
       // Quoted fields. 
 
       "(?:\"([^\"]*(?:\"\"[^\"]*)*)\"|" + 
 

 
       // Standard fields. 
 
       "([^\"\\" + strDelimiter + "\\r\\n]*))" 
 
      ), 
 
      "gi" 
 
      ); 
 

 

 
     // Create an array to hold our data. Give the array 
 
     // a default empty first row. 
 
     var arrData = [[]]; 
 

 
     // Create an array to hold our individual pattern 
 
     // matching groups. 
 
     var arrMatches = null; 
 

 

 
     // Keep looping over the regular expression matches 
 
     // until we can no longer find a match. 
 
     while (arrMatches = objPattern.exec(strData)){ 
 

 
      // Get the delimiter that was found. 
 
      var strMatchedDelimiter = arrMatches[ 1 ]; 
 

 
      // Check to see if the given delimiter has a length 
 
      // (is not the start of string) and if it matches 
 
      // field delimiter. If id does not, then we know 
 
      // that this delimiter is a row delimiter. 
 
      if (
 
       strMatchedDelimiter.length && 
 
       strMatchedDelimiter !== strDelimiter 
 
       ){ 
 

 
       // Since we have reached a new row of data, 
 
       // add an empty row to our data array. 
 
       arrData.push([]); 
 

 
      } 
 

 
      var strMatchedValue; 
 

 
      // Now that we have our delimiter out of the way, 
 
      // let's check to see which kind of value we 
 
      // captured (quoted or unquoted). 
 
      if (arrMatches[ 2 ]){ 
 

 
       // We found a quoted value. When we capture 
 
       // this value, unescape any double quotes. 
 
       strMatchedValue = arrMatches[ 2 ].replace(
 
        new RegExp("\"\"", "g"), 
 
        "\"" 
 
        ); 
 

 
      } else { 
 

 
       // We found a non-quoted value. 
 
       strMatchedValue = arrMatches[ 3 ]; 
 

 
      } 
 

 

 
      // Now that we have our value string, let's add 
 
      // it to the data array. 
 
      arrData[ arrData.length - 1 ].push(strMatchedValue); 
 
     } 
 

 
     // Return the parsed data. 
 
     return(arrData); 
 
    } 
 

 
</script>