views:

28

answers:

1

I can decode the points, I just need to figure out how to loop through the array of points and produce

[
new google.maps.LatLng(39.112456,-84.574779),
new google.maps.LatLng(39.314153,-84.261379),
new google.maps.LatLng(39.197099,-84.667579),
new google.maps.LatLng(39.16836,-84.479381)
];

Code available at http://pastebin.com/Zf6hi4AB

Any help is appreciated.

<!--- this is the original function --->
function decodeLine (encoded) {
  var len = encoded.length;
  var index = 0;
  var array = [];
  var lat = 0;
  var lng = 0;

  while (index < len) {
    var b;
    var shift = 0;
    var result = 0;
    do {
      b = encoded.charCodeAt(index++) - 63;
      result |= (b & 0x1f) << shift;
      shift += 5;
    } while (b >= 0x20);
    var dlat = ((result & 1) ? ~(result >> 1) : (result >> 1));
    lat += dlat;

    shift = 0;
    result = 0;
    do {
      b = encoded.charCodeAt(index++) - 63;
      result |= (b & 0x1f) << shift;
      shift += 5;
    } while (b >= 0x20);
    var dlng = ((result & 1) ? ~(result >> 1) : (result >> 1));
    lng += dlng;

    array.push([lat * 1e-5, lng * 1e-5]);
  }

  return array;




<!---  this is what i am trying --->
function decodeLine(encoded) {
  var len = encoded.length;
  var index = 0;
  var array = [];
  var lat = 0;
  var lng = 0;

  while (index < len) {
    var b;
    var shift = 0;
    var result = 0;
    do {
      b = encoded.charCodeAt(index++) - 63;
      result |= (b & 0x1f) << shift;
      shift += 5;
    } while (b >= 0x20);
    var dlat = ((result & 1) ? ~(result >> 1) : (result >> 1));
    lat += dlat;

    shift = 0;
    result = 0;
    do {
      b = encoded.charCodeAt(index++) - 63;
      result |= (b & 0x1f) << shift;
      shift += 5;
    } while (b >= 0x20);
    var dlng = ((result & 1) ? ~(result >> 1) : (result >> 1));
    lng += dlng;

    array.push([new google.maps.LatLng(lat * 1e-5, lng * 1e-5)]);
  }

  return array;
}




<!--- this is how i trying to use it --->
var polygon_#fips#Coords = [];
    var polygon_#fips#Coords = [decodeLine('#points#')];
    var polygon_#fips#;


    polygon_#fips# = new google.maps.Polygon({
      paths: polygon_#fips#Coords,
      strokeColor: "##FF0000",
      strokeOpacity: 0.8,
      strokeWeight: 3,
      fillColor: "###polyfillcolor#",
      fillOpacity: 0.35
    });

    polygon_#fips#.setMap(map);

<!--- this is the orinigal use --->
var polygon_#fips#Coords = [];
    var polygon_#fips#Coords = [
            new google.maps.LatLng(39.112456,-84.574779),
            new google.maps.LatLng(39.314153,-84.261379),
            new google.maps.LatLng(39.197099,-84.667579),
            new google.maps.LatLng(39.16836,-84.479381)
    ];

    var polygon_#fips#;


    polygon_#fips# = new google.maps.Polygon({
      paths: polygon_#fips#Coords,
      strokeColor: "##FF0000",
      strokeOpacity: 0.8,
      strokeWeight: 3,
      fillColor: "###polyfillcolor#",
      fillOpacity: 0.35
    });

    polygon_#fips#.setMap(map);
+1  A: 

OK I think I see what you're saying. Try changing

 var polygon_#fips#Coords = [decodeLine('#points#')];

to

 var polygon_#fips#Coords = decodeLine('#points#');

Also in decodeLine() change

 array.push([new google.maps.LatLng(lat * 1e-5, lng * 1e-5)]);

to

 array.push(new google.maps.LatLng(lat * 1e-5, lng * 1e-5));

What you were doing is adding a new array of google.maps.LatLng to the end of your array, so you ended up with an array of arrays of google.maps.LatLng. With this change, you should end up with an array of google.maps.LatLng, which is what you need.

LarsH
No error reported in firebug, just no polygons on the map, I have tested the encoded points in v2 and it worked fine. Complete ColdFusion code here http://pastebin.com/FE08TzFN Thanks for you help.
cfEngineers
The original function just produced points(39.314153,-84.261379) in an array bu ti need to output new google.maps.LatLng(39.314153,-84.261379) in an array not sure how to do it, i think probably use the original function and somehow reiterate through the returned array to make a new array with the new google.maps.LatLng(points[0],points[1]) in it, that is where i am stuck.
cfEngineers
@cfEngineers: just saw something else. See my updated answer...
LarsH
LarsH, that totally did the trick! I have been sweating this for some time. Point me to your wish list. Thanks, Ernie
cfEngineers
@cfEngineers, you're the first one who's asked me about a wishlist. If you want you can give a donation to http://www.samaritanspurse.org/. Glad to help.
LarsH