provide-free-support Ujjwal's Blog: Google Maps API used to map multiple locations.

Friday, March 26, 2010

Google Maps API used to map multiple locations.

Hi,

I was recently working on a project where i need to fetch multiple locations used google maps API. I searched a lot and tried many examples but was'nt able to find any appropriate, finally i gone through the documentation of google maps API. I found the solution

Below is the list where i stored all my addresses


var addresses =new Array();

addresses[] = '';



Here's my onload function


function load() {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(10, -180), 13);
        map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());

        geocoder = new GClientGeocoder();
      
        GEvent.addListener(map, 'click', function(overlay, point) {
     if (point) {
       //document.getElementById("show_x").innerHTML = point.x;
       // document.getElementById("show_y").innerHTML = point.y;
     }
   });
  
   GEvent.addListener(map, 'zoomend',
                       function(oldZoomLevel, newZoomLevel) {
     //document.getElementById("zoom_old").innerHTML = oldZoomLevel;
     //document.getElementById("zoom_new").innerHTML = newZoomLevel;
   });
  
     }

showAddress();
    }

Here's my show address function


 function showAddress() {
       //alert("address : " + addresses);
     convertToLatLng();
    }

Here's my convertToLatLng, this function is the core function i used for


 var points = [];
    function convertToLatLng() {
      if (points.length >= addresses.length) {
        showPoints();
      } else {
        geocode(addresses[points.length]);
      }
    }

My geocode function


 function geocode(address) {
//alert(address);
   geocoder.getLatLng(
          address,
          function(point) {
          
           if(!point)
           {
          
           }
           else
           {
              points.push(point);
              window.setTimeout(convertToLatLng, 300);
              map.setCenter(point, 13);
             //var marker = new GMarker(point);
             var letters=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P", "Q","R","S","T","U","V","W","X","Y","Z"];
            
             var marker=createMarker(point, letters[points.length-1]);

              map.addOverlay(marker);
              //marker.openInfoWindowHtml(address + "
Long: " + point.x + "
Lati:  " + point.y);
              //document.getElementById("show_x").innerHTML = point.x;
        //document.getElementById("show_y").innerHTML = point.y;
        //document.getElementById("zoom_new").innerHTML = 14;
            }
          }
        );
    }

My show points function, this function displays points for each location fetched from the database


function showPoints() {
      for (i in points) {
        var lat_lng = points[i];
        if (lat_lng) {
          var marker=createMarker(points[i], letters[i]);
 map.addOverlay(marker);
          //map.addOverlay(new GMarker(lat_lng));
        }
      }
    }

I tweaked a bit and created alphabetical markers for the map as below


     function createMarker(point, letter) {
    // use a custom icon with letter A - Z


var letter = letter;
var myIcon = new GIcon(G_DEFAULT_ICON, "http://www.google.com/mapfiles/marker" + letter + ".png");
myIcon.printImage = "http://maps.google.com/mapfiles/marker"+letter+"ie.gif";
myIcon.mozPrintImage = "http://maps.google.com/mapfiles/marker"+letter+"ff.gif";
var CallSign = CallSign;
var marker = new GMarker(point, {icon:myIcon});
//GEvent.addListener(marker, "click", function()
//{
//
//// save the info we need to use later for the side_bar
//gmarkers.push(marker)
//// add a line to the side_bar html
//
//
//
//});
return marker;
}

This is how i did to display multiple locations on the map.

Cheers!!!

Ujjwal








 

No comments:

best-it-exam-    | for-our-work-    | hottst-on-sale-    | it-sale-    | tast-dumps-us-    | test-king-number-    | pass-do-it-    | just-do-it-    | pass-with-us-    | passresults-everything-    | passtutor-our-dumps-    | realtests-us-exam-    | latest-update-source-for-    | cbtnuggets-sale-exam    | experts-revised-exam    | certguide-sale-exam    | test4-sale-exam    | get-well-prepared-    | certkiller-sale-exam    | buy-discount-dumps    | how-to-get-prepared-for-the    | in-an-easy-way    | brain-dumps-sale    | with-pass-exam-guarantee    | accurate-study-material    | at-first-try    | 100%-successful-rate    | get-certification-easily    | material-provider-exam    | real-exam-practice    | with-pass-score-guarantee    | certification-material-provider    | for-certification-professionals    | get-your-certification-successfully    | 100%-Pass-Rate    | in-pdf-file    | practice-exam-for    | it-study-guides    | study-material-sku    | study-guide-pdf    | prep-guide-demo    | certification-material-id    | actual-tests-demo    | brain-demos-test    | best-pdf-download    | our-certification-material    | best-practice-test    | leading-provider-on    | this-course-is-about    | the-most-reliable    | high-pass-rate-of    | high-pass-rate-demo    | recenty-updated-key    | only-for-students-free-download    | courseware-plus-kit-for    | accurate-answers-of    | the-most-reliable-id    | provide-training-for    | welcome-to-buy    | material-for-success-pass    | provide-free-support    | best-book-for-pass    | accuracy-of-the-answers    | pass-guarantee-id    | pass-exam-key    | pass-sku-id    | study-for-exid    | pdf-sku-exid    | sku-pdf-id    | pdf-demo-key    | exam-demo-ske    | pass-it-dump    |
http://www.menuiserie-dauvergne.com/    | http://www.menuiserie-dauvergne.com/    |