2010-09-14 4 views
0

Je peux décoder les points, je juste besoin de savoir comment faire une boucle à travers le réseau de points et produireAPI GoogleMaps polygones v3 de problème, un tableau encodée

[ 
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 disponible à http://pastebin.com/Zf6hi4AB

Tous l'aide est appréciée.

<!--- 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); 
+0

Une partie de votre code n'a pas été formatée en tant que code. – LarsH

+0

Vous nous avez montré votre code et ce que vous voulez qu'il fasse. Vous essayez 'array.push ([nouveau google.maps.LatLng (lat * 1e-5, lng * 1e-5)])' 'Il serait utile si vous indiquez comment votre tentative actuelle échoue. Par exemple. Y a-t-il une erreur? ou le tableau est vide? ou...? – LarsH

+0

Code disponible à http://pastebin.com/Zf6hi4AB – cfEngineers

Répondre

1

OK Je pense que je vois ce que vous dites. Essayez de changer

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

à

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

également dans decodeLine() changement

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

à

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

Ce que vous faites est d'ajouter un nouveau tableau de google. maps.LatLng à la fin de votre tableau, de sorte que vous ende d avec un tableau de tableaux de google.maps.LatLng. Avec cette modification, vous devriez vous retrouver avec un tableau de google.maps.LatLng, ce dont vous avez besoin.

+0

Aucune erreur signalée dans firebug, juste aucun polygone sur la carte, j'ai testé les points encodés en v2 et ça a bien fonctionné. Complétez le code ColdFusion ici http://pastebin.com/FE08TzFN Merci pour votre aide. – cfEngineers

+0

La fonction d'origine vient de produire des points (39.314153, -84.261379) dans un tableau bu ti besoin de sortir de nouveaux google.maps.LatLng (39.314153, -84.261379) dans un tableau ne sais pas comment le faire, je pense utiliser probablement la fonction d'origine et en quelque sorte réitérer à travers le tableau retourné pour faire un nouveau tableau avec le nouveau google.maps.LatLng (points [0], points [1]), c'est là que je suis coincé. – cfEngineers

+0

@ cfEngineers: juste vu quelque chose d'autre. Voir ma mise à jour de réponse ... – LarsH

Questions connexes