|
40 | 40 | } |
41 | 41 | return JSON.parse(jsonizeFilter(input)); |
42 | 42 | }; |
43 | | - |
| 43 | + |
44 | 44 | var getLatLng = function(input) { |
45 | 45 | var output = input; |
46 | | - if (input[0].constructor == Array) { // [[1,2],[3,4]] |
47 | | - output = input.map(function(el) { |
48 | | - return new google.maps.LatLng(el[0], el[1]); |
49 | | - }); |
50 | | - } else if(!isNaN(parseFloat(input[0])) && isFinite(input[0])) { |
| 46 | + if (input[0].constructor == Array) { |
| 47 | + if ((input[0][0].constructor == Array && input[0][0].length == 2) || input[0][0].constructor == Object) { |
| 48 | + var preoutput; |
| 49 | + var outputArray = []; |
| 50 | + for (var i = 0; i < input.length; i++) { |
| 51 | + preoutput = input[i].map(function(el){ |
| 52 | + return new google.maps.LatLng(el[0], el[1]); |
| 53 | + }); |
| 54 | + outputArray.push(preoutput); |
| 55 | + } |
| 56 | + output = outputArray; |
| 57 | + } else { |
| 58 | + output = input.map(function(el) { |
| 59 | + return new google.maps.LatLng(el[0], el[1]); |
| 60 | + }); |
| 61 | + } |
| 62 | + } else if (!isNaN(parseFloat(input[0])) && isFinite(input[0])) { |
51 | 63 | output = new google.maps.LatLng(output[0], output[1]); |
52 | 64 | } |
53 | 65 | return output; |
|
61 | 73 | try { // 2. JSON? |
62 | 74 | var output = getJSON(input); |
63 | 75 | if (output instanceof Array) { |
64 | | - // [{a:1}] : not lat/lng ones |
65 | 76 | if (output[0].constructor == Object) { |
66 | 77 | output = output; |
67 | | - } else { // [[1,2],[3,4]] or [1,2] |
68 | | - output = getLatLng(output); |
| 78 | + } else if (output[0] instanceof Array) { |
| 79 | + if (output[0][0].constructor == Object) { |
| 80 | + output = output; |
| 81 | + } else { |
| 82 | + output = getLatLng(output); |
| 83 | + } |
| 84 | + } else { |
| 85 | + output = getLatLng(output); |
69 | 86 | } |
70 | 87 | } |
71 | 88 | // JSON is an object (not array or null) |
|
0 commit comments