Google Map not showing all markers from retrieved addresses -


good day,

i trying add markers on google map not markers show. first address marker shows. please see below code:

//search button event handler function getaccounts() {      //search city contains data     var search = searchtext.value;     //alert("you have inserted: " + search + " city");     if (search != "") {         retrievemultiple("accountset", "substringof('" + search + "',address1_city)", searchcompleted, null);     }      //retrieve accounts     else {         retrievemultiple("accountset", null, searchcompleted, null);     } }  //callback - search success function searchcompleted(data, textstatus, xmlhttprequest) {      if (data && data.length > 0) {           (var i=0; < data.length; i++) {                             var result = data[i];             var address = (data[i].address1_line1 + ", " + data[i].address1_city + ", " + data[i].address1_stateorprovince + ", " + data[i].address1_country);              showaddress(address);              alert(result.address1_line1 + ", " +result.address1_city + ", " + result.address1_stateorprovince + ", " + result.address1_country);         }     }     else {         alert('no records!');     } }   function showaddress(address) {     var geocoder = new google.maps.geocoder();     geocoder.geocode({ 'address': address}, function (result, status) {         if (status == google.maps.geocoderstatus.ok) {              var myoptions = {                 zoom: 3,                 center: result[0].geometry.location,                 maptypeid: google.maps.maptypeid.roadmap             };             var map = new google.maps.map(document.getelementbyid("map"), myoptions);             //map.setcenter(result[0].geometry.location);             var marker = new google.maps.marker({                 map: map,                 position: result[0].geometry.location             });         } else {             alert("geocode not successful following reason: "+ status); // address not found         }     });  }  // ]]> 

i know information retrieved because alert() shows retrieved information

your showaddress function creates new map each marker. if want show more one, need create 1 map , add markers it. change this:

function showaddress(address) {   var geocoder = new google.maps.geocoder();   geocoder.geocode({ 'address': address}, function (result, status) {     if (status == google.maps.geocoderstatus.ok) {       // creates new map object       var myoptions = {         zoom: 3,         center: result[0].geometry.location,         maptypeid: google.maps.maptypeid.roadmap       };       var map = new google.maps.map(document.getelementbyid("map"), myoptions);       //map.setcenter(result[0].geometry.location);       var marker = new google.maps.marker({         map: map,         position: result[0].geometry.location       });     } else {       alert("geocode not successful following reason: "+ status); // address not found     }   }); } 

to this:

function showaddress(address, map) {   var geocoder = new google.maps.geocoder();   geocoder.geocode({ 'address': address}, function (result, status) {     if (status == google.maps.geocoderstatus.ok) {       var marker = new google.maps.marker({         map: map,         position: result[0].geometry.location       });     } else {       alert("geocode not successful following reason: "+ status); // address not found     }   }); } 

and create map before call (somewhere outside of code have posted).


Comments

Popular posts from this blog

javascript - JS causing window size to be bigger than necessary - Dropdown bug -

php - Calling a template part from a post -

How to mention the localhost in android -