Hello Rossko,

Your tips were very helpful to me thanks
I had only a limited time and by the time I had to set aside (sadly
some of your suggestions).



"It is slow, and if the geocoder Makes A Mistake"

As for the error on the discovery of the address I fix enabling the
operator can change the address in a way that is readable by the
geocoder.


"Yes, do not store your geocode addresses Every time the page is
viewed.

The page is loaded all the stores because I seek not avnedoli already
included in the database in the form: City, Province, State / Country,
address. depending on the store interogo to search the database
according to its city and state in order to further weed out the DB.

"Gecoding is asynchronous; your 1000ms delay is a kludge and is not
the correct way to use asynchronous services. "

is very interesting when I have more time to get their hands on this
program I try to improve it as you say.

Thanks:)

Eventually I succeeded, and the function does what it should do.
I'll put you below XD



 // Prepare this list from ColdFusion
    locations = new Array();
    InfoString = new Array();
    //Ja è la latitudine del mio negozio preso in esame
    var CentroLat;
    //Ka è la longitudine del mio negozio preso in esame
    var CentroLang;

    //Ja è la latitudine del mio negozio che mi permette di ricavare
la distanza  in confronto al mio centro
    var StoreLat;
    //Ka è la longitudine del mio negozio che mi permette di ricavare
la distanza in confronto al mio centro
    var StoreLang;

    var map;
    var geocoder;


    var image;
    var zoom;
    var visual;




    var index = 0;

    var geocoderFunction = function() {

        if (index == 0) {

            //var test = findObjWithClientId("hd_ind");
            //elenco = test.value;
            //locations = elenco.split("|");

            image = "0"


            locations[0] = "Piazza Maggiore, 40128, Bologna, Emilia
Romagna"
            locations[1] = "Vicolo San Giobbe, 40128, Bologna, Emilia
Romagna"
            locations[2] = "Via Monte Grappa, 40128, Bologna, Emilia
Romagna"
            locations[3] = "Via Barberia, 40128, Bologna, Emilia
Romagna"
            locations[4] = "Via Riva di reno, 40128, Bologna, Emilia
Romagna"
            locations[5] = "Via Marsala, 40128, Bologna, Emilia
Romagna"
            locations[6] = "Via Bocca di Lupo, 40128, Bologna, Emilia
Romagna"
            locations[7] = "Via Roma, 40128, Granarolo Emilia,Bologna,
Emilia Romagna"


            InfoString[0] = "Piazza Maggiore, 40128, Bologna, Emilia
Romagna"
            InfoString[1] = "Vicolo San Giobbe, 40128, Bologna, Emilia
Romagna"
            InfoString[2] = "Via Monte Grappa, 40128, Bologna, Emilia
Romagna"
            InfoString[3] = "Via Barberia, 40128, Bologna, Emilia
Romagna"
            InfoString[4] = "Via Riva di reno, 40128, Bologna, Emilia
Romagna"
            InfoString[5] = "Via Marsala, 40128, Bologna, Emilia
Romagna"
            InfoString[6] = "Via Bocca di Lupo, 40128, Bologna, Emilia
Romagna"
            InfoString[7] = "Via Roma, 40128, Granarolo
Emilia,Bologna, Emilia Romagna"



            //var test = findObjWithClientId("hd_desc");
            //desc = test.value;
            //InfoString = desc.split("||");

            //var testimage = findObjWithClientId("hd_image");
            //image = testimage.value;

            //var TestzoomMap = findObjWithClientId("hd_zoom");
            //zoomMap = parseInt(TestzoomMap.value);

            var mapOpt = {
                mapTypeId: google.maps.MapTypeId.ROADMAP
                //center: new google.maps.LatLng(38.00, -100.00),
                //zoom: 6
            };

            map = new
google.maps.Map(document.getElementById("map_canvas"), mapOpt);

            geocoder = new google.maps.Geocoder();

        }



        geocoder.geocode({ 'address': locations[index] },
function(results, status) {
            //document.write(status + " ; ");
            if (status == google.maps.GeocoderStatus.OK) {
                if (index == 0) {
                    map.setCenter(results[0].geometry.location);
                    map.setZoom(8);

                    Centro = results[0].geometry.location;

                    // Cerchio Sulla Mappa
                    var circle = new google.maps.Circle({
                        center: results[0].geometry.location,
                        map: map,
                        radius: 1000 // 1 km
                    });

                    CentroLat = results[0].geometry.location.Ja;

                    CentroLang = results[0].geometry.location.Ka;

                }

                //                if (index != 0) {
                StoreLat = results[0].geometry.location.Ja;
                StoreLang = results[0].geometry.location.Ka;

                var distanza;



                distanza = distance(CentroLat, CentroLang, StoreLat,
StoreLang);

                //                }
                //alert(distanza);

                if (distanza < 30.00) {

                    //Creo la mia infowindows
                    var infowindow = new google.maps.InfoWindow({
                        content: InfoString[index]
                    });

                    if (image == "0") {
                        var marker = new google.maps.Marker
                           ({ map: map,
                               position: results[0].geometry.location,
                               animation: google.maps.Animation.DROP,
                               title: "Imperial Store"
                               //icon: "images/fumetto.png"
                           });
                    };
                    if (image == "1") {
                        var marker = new google.maps.Marker
                           ({ map: map,
                               position: results[0].geometry.location,
                               animation: google.maps.Animation.DROP,
                               title: "Imperial Headquarter -
Showroom"
                               //icon: "../../images/fumettoHQ.png"
                           });
                    };

                    //A Ogni ciclo assegno alla al mio Marker una
Infowindows che si aprirà al click del mouse
                    google.maps.event.addListener(marker, 'click',
function() {
                        infowindow.open(map, marker);
                    });



                }

            }

            else {

                alert(status + " alla posizione " + locations[index]);


            }

            // Call the geocoder with a 1000ms delay
            index++;
            if (locations.length > index) {
                setTimeout(geocoderFunction, 1000);
            }
        });
        if (index == locations.length) {

            index = 0;


        }
    }



    // funzione per calcolare la distanza in base alle coordinate
    function distance(lat1,lon1,lat2,lon2) {


    var dist;

    var R = 6371; // km (change this constant to get miles)

    var dLat = (lat2-lat1) * Math.PI / 180;

    var dLon = (lon2-lon1) * Math.PI / 180;

    var a = Math.sin(dLat/2) * Math.sin(dLat/2) +

        Math.cos(lat1 * Math.PI / 180 ) * Math.cos(lat2 * Math.PI /
180 ) *

        Math.sin(dLon/2) * Math.sin(dLon/2);

    var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));

    var d = R * c;

//   if (d>1) return Math.round(d)+"km";
    //    else if (d<=1) return Math.round(d*1000)+"m";

  dist=(Math.round(d * 1000))/1000;



    return dist;

}

-- 
You received this message because you are subscribed to the Google Groups 
"Google Maps JavaScript API v3" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-maps-js-api-v3?hl=en.

Reply via email to