Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>following steps you have to follow. 1. make a list of your addresses in javascript aaray. 2. make a utility function to geocode and then put marker by passing address as arguement. 3. iterate over your addresses array and call your marker utility function. </p> <p>example: map.jsp :: it tales input json string that is list of addresses and the converts it to javascript array: add the jquery and infobox.js by downloading fron google.</p> <pre><code> &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt; &lt;%@ page contentType="text/html;charset=windows-1252"%&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="content-type" content="text/html; charset=UTF-8" /&gt; &lt;title&gt;Google Maps Multiple Markers&lt;/title&gt; &lt;script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"&gt;&lt;/script&gt; &lt;script language="JavaScript" src="js/jquery-1.8.0.min.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script language="JavaScript" src="js/infobox.js" type="text/javascript"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;% String json=request.getParameter("address"); %&gt; &lt;input type="hidden" id="json" value="&lt;%=json%&gt;"&gt;&lt;/input&gt; &lt;div id="map" style="width: 1250px; height: 500px;" align="center"&gt;&lt;/div&gt; &lt;script type="text/javascript" language="JavaScript" src="js/map.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; var jsonvalue=document.getElementById("json").value; var use=unescape(jsonvalue); //alert(use); var obj = eval ("(" + use + ")"); var cobj=obj.center; var olist=obj.other; codeproject(cobj.center_add,cobj.center_name); //alert(cobj.center_name+" and "+cobj.center_add); for(var i=0;i&lt;olist.length;i++) { //alert(olist[i].other_add); codeAddress(olist[i].other_add,olist[i].other_name); } &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><em><strong></em>__<em>_</em>__<em>_</em>__</strong><em>map.js</em><strong><em>_</em>__<em>_</em>__<em>_</em>_</strong></p> <pre><code> //used by infowindow //the googlemap code var geocoder = new google.maps.Geocoder(); //var infowindow = new google.maps.InfoWindow(); var LatLngList = new Array(6); var i; var infowindow = new google.maps.InfoWindow(); var markerBounds = new google.maps.LatLngBounds(); var markerarray=new Array(); //making the div for window popup var boxText = document.createElement("div"); boxText.style.cssText = "border: 2px solid Gray; margin-top: 6px; background: white; padding: 5px;font-weight: bold;color: Gray;"; boxText.innerHTML = " "; //options array for infobox window var myOptions = { map:map, content : boxText, disableAutoPan : false, maxWidth : 0, pixelOffset : new google.maps.Size( - 140, 0), zIndex : null, boxStyle : { background : "url('tipbox.gif') no-repeat", width : "280px" }, closeBoxMargin : "10px 4px 2px 2px", closeBoxURL : "close.gif", infoBoxClearance : new google.maps.Size(1, 1), isHidden : false, pane : "floatPane", enableEventPropagation : true }; var infoBox; function codeproject(address, client) { geocoder.geocode( { 'address' : address }, function (results, status) { if (status == google.maps.GeocoderStatus.OK) { map.setCenter(results[0].geometry.location); var marker = new google.maps.Marker( { map : map, icon : 'green-dot.png', position : results [0].geometry.location, draggable : false, animation : google.maps.Animation.DROP }); //bounce the marker // marker.setAnimation(google.maps.Animation.BOUNCE); //initialize info box infoBox = new InfoBox(myOptions); markerBounds.extend(results[0].geometry.location); //listeners google.maps.event.addListener(marker, 'mouseover', function () { //stop bouncing // marker.setAnimation(null); // $("img[src$='iws3.png']").hide(); // infowindow.setContent('&lt;b&gt;' + client + '&lt;\/b&gt;&lt;br&gt;'+ results[0].formatted_address); // infowindow.open(map, this); boxText.innerHTML = "&lt;br&gt;"+client +"&lt;br&gt;"+results[0].formatted_address; infoBox.setContent(boxText,marker); infoBox.open(map,marker); }); google.maps.event.addListener(marker, 'mouseout', function () { // infowindow.close(); infoBox.close(); //start bounce // marker.setAnimation(google.maps.Animation.BOUNCE); }); //ok end } else { if (status == google.maps.GeocoderStatus.OVER_QUERY_LIMIT) { alert("Error Occured during geocode:" + status); } // alert('Geocode was not successful for '+client +' the following reason: ' + status); } }); } function codeAddress(address, client) { // var address = document.getElementById('address').value; geocoder.geocode( { 'address' : address }, function (results, status) { if (status == google.maps.GeocoderStatus.OK) { // map.setCenter(results[0].geometry.location); infoBox = new InfoBox(myOptions); var marker = new google.maps.Marker( { map : map, // icon : 'smallpin.png', position : results[0].geometry.location, draggable : false, animation : google.maps.Animation.DROP }); //make bounds //bounce the marker // marker.setAnimation(google.maps.Animation.BOUNCE); //initialize info box markerBounds.extend(results[0].geometry.location); //listeners google.maps.event.addListener(marker, 'mouseover', function () { //stop bouncing // marker.setAnimation(null); $("img[src$='iws3.png']").hide(); // infowindow.setContent('&lt;b&gt;' + client + '&lt;\/b&gt;&lt;br&gt;'+ results[0].formatted_address + '&lt;\br&gt;'); //infowindow.open(map, this); boxText.innerHTML = "&lt;br&gt;"+client +"&lt;br&gt;"+results[0].formatted_address ; infoBox.setContent(boxText,marker); infoBox.open(map,marker); }); google.maps.event.addListener(marker, 'mouseout', function () { // infowindow.close(); //start bounce infoBox.close(); // marker.setAnimation(google.maps.Animation.BOUNCE); }); //ok end } else { // alert('Geocode was not successful for '+client +' the following reason: ' + status); } }); } //////////////calling the above two functions var centerpoint = new google.maps.LatLng(43.652527, - 79.381961);//for ontario canada zoom level-7 //map intializing var map = new google.maps.Map(document.getElementById('map'), { zoom : 4, backgroundColor : '#B5B5B5', draggable : true, center : centerpoint, mapTypeId : google.maps.MapTypeId.ROADMAP }); ///geocoding multiple addresses //bounce markers function toggleBounce(mark) { if (mark.getAnimation() != null) { mark.setAnimation(null); } else { mark.setAnimation(google.maps.Animation.BOUNCE); } } ///// function putmarker(address,client,lat,lng) { var position = new google.maps.LatLng(lat,lng); var marker = new google.maps.Marker( { map : map, icon : 'green-dot.png', position : position, draggable : false, animation : google.maps.Animation.DROP }); //bounce the marker // marker.setAnimation(google.maps.Animation.BOUNCE); //initialize info box infoBox = new InfoBox(myOptions); markerBounds.extend(position); //listeners google.maps.event.addListener(marker, 'mouseover', function () { //stop bouncing // marker.setAnimation(null); // $("img[src$='iws3.png']").hide(); // infowindow.setContent('&lt;b&gt;' + client + '&lt;\/b&gt;&lt;br&gt;'+ results[0].formatted_address); // infowindow.open(map, this); boxText.innerHTML = "&lt;br&gt;"+client +"&lt;br&gt;"+address; infoBox.setContent(boxText,marker); infoBox.open(map,marker); }); google.maps.event.addListener(marker, 'mouseout', function () { // infowindow.close(); infoBox.close(); //start bounce // marker.setAnimation(google.maps.Animation.BOUNCE); }); //ok end } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload