You need to sign in to do that
Don't have an account?
Saikiran Kolli
Google map integration with salesforce
Hi,
I was trying to integrate salesforce with google map, But I'm able to see only 10 addresses. Please help me
I was trying to integrate salesforce with google map, But I'm able to see only 10 addresses. Please help me
<apex:page controller="clsMultipleMarker" sidebar="false"> <script type="text/javascript" src="https://maps.google.com/maps/api/js?sensor=false"></script> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> <apex:form > <apex:pageBlock > <apex:pageMessages rendered="true" id="msg"></apex:pageMessages> <script type="text/javascript"> var map; function initMap() { var mapDiv = document.getElementById('map'); map = new google.maps.Map(mapDiv, { center: {lat: 44.540, lng: -78.546}, zoom: 8 }); } function showMarkers(){ var addressArray = {!listOfAddresses}; // Use this format to fill addressArray alert("say hello") var geocoder = new google.maps.Geocoder(); var markerBounds = new google.maps.LatLngBounds(); for (var i = 0; i < addressArray.length; i++) { geocoder.geocode( { 'address': addressArray[i]}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { var marker = new google.maps.Marker({ map: map, position: results[0].geometry.location }); marker.setIcon({ // THIS CODE MAKES THE MARKER CIRCLE path: google.maps.SymbolPath.CIRCLE, scale: 5, fillColor: " #FF0000", fillOpacity:50, strokeWeight: 0 }) markerBounds.extend(results[0].geometry.location); map.fitBounds(markerBounds); } else { alert("Geocode was not successful for the following reason: " + status); } }); } } function showActiveUsers(){ // alert("Please Select Your Location"); var activeaddressArray = {!listOfActiveAddresses}; // Use this format to fill addressArray alert(activeaddressArray); var geocoder = new google.maps.Geocoder(); var markerBounds = new google.maps.LatLngBounds(); for (var i = 0; i < activeaddressArray.length; i++) { geocoder.geocode( { 'address': activeaddressArray[i]}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { var marker = new google.maps.Marker({ map: map, position: results[0].geometry.location }); marker.setIcon({ // THIS CODE MAKES THE MARKER CIRCLE path: google.maps.SymbolPath.CIRCLE, scale: 5, fillColor: "rgb(0,0,255)", fillOpacity:50, strokeWeight: 0 }) markerBounds.extend(results[0].geometry.location); map.fitBounds(markerBounds); } else { alert("Please click ok to continue"); //alert("Geocode was not successful for the following reason: " + status); } }); } } function showInActiveUsers(){ // alert("Please Select Your Location"); var inactiveaddressArray = {!listOfInActiveAddresses}; // Use this format to fill addressArray alert(inactiveaddressArray); var geocoder = new google.maps.Geocoder(); var markerBounds = new google.maps.LatLngBounds(); for (var i = 0; i < inactiveaddressArray.length; i++) { geocoder.geocode( { 'address': inactiveaddressArray[i]}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { var marker = new google.maps.Marker({ map: map, position: results[0].geometry.location }); marker.setIcon({ // THIS CODE MAKES THE MARKER CIRCLE path: google.maps.SymbolPath.CIRCLE, scale: 5, fillColor: "rgb(0,255,0)", fillOpacity:50, strokeWeight: 0 }) markerBounds.extend(results[0].geometry.location); map.fitBounds(markerBounds); } else { alert("Geocode was not successful for the following reason: " + status); } }); } } //-------------------------------------------------------------------------------------------------------- $(document).ready(function(){ initMap(); }); </script> <style> #map { font-family: Arial; font-size:12px; line-height:normal !important; height:500px; width: 800px; background:transparent; } </style> <div id="map"></div> <apex:outputLabel >Enter Your Location</apex:outputLabel> <!--<apex:inputText value="{!ajay}"/> <apex:commandButton value="Get Location" action="{!GetAddressLocation}"/>--> <apex:selectList value="{!ajay}" multiselect="false" size="1"> <apex:selectOptions value="{!lstSelectOption}"></apex:selectOptions> <apex:actionSupport event="onchange" action="{!GetAddressLocation}"/> </apex:selectList> <!--<input type="button" value="Show All Users" onclick="showMarkers();"/> --> <input type="button" value="Show Active Users" onclick="showActiveUsers();"/> <input type="button" value="Show InActive Users" onclick="showInActiveUsers();"/> </apex:pageBlock> </apex:form> </apex:page> public class clsMultipleMarker{ public String ajay {get;set;} public List<String> listOfAddresses {get; set;} public List<String> listOfActiveAddresses {get; set;} public List<String> listOfInActiveAddresses {get; set;} public list<selectOption> lstSelectOption{get;set;} List<Student__c> lstStudent{set;get;} public clsMultipleMarker() { ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Please Select Your Location Below')); listOfAddresses = new List<String>(); listOfActiveAddresses = new List<String>(); listOfInActiveAddresses = new List<String>(); lstStudent = new List<Student__c>(); //get All Location in Drop down lstSelectOption=new List<SelectOption>(); List<Location__c> lstLocation=[select Id,name from Location__c]; lstSelectOption.add(new SelectOption('','Select Location')); for(Location__c lc:lstLocation){ lstSelectOption.add(new SelectOption(lc.Id,lc.Name)); } } public pagereference GetAddressLocation(){ listOfAddresses = new List<String>(); /* List<Student__c> lstStudent=[select Apt_No__c,Street_Address__c, City__c, State__c,PostalCode__c, Country__c, Location__r.Name from Student__c where City__c!=null and Location__c=:ajay]; System.debug('list of students ============================>'+ lstStudent); System.debug('keyword ============================>'+ ajay); if(lstStudent!=null && lstStudent.size()>0){ for(Student__c acc:lstStudent){ listOfAddresses.add('"'+acc.Street_Address__c+','+acc.City__c+','+acc.State__c+','+acc.PostalCode__c+','+acc.Country__c +'"'); } } */ List<Student__c> lstActiveStudent=[select id,Apt_No__c, Street_Address__c, City__c, State__c,PostalCode__c, Country__c from Student__c where City__c!=null and Status__c='Active' and Location__c=:ajay]; if(lstActiveStudent!=null && lstActiveStudent.size()>0){ for(Student__c acc:lstActiveStudent){ listOfActiveAddresses .add('"'+acc.Street_Address__c+','+acc.City__c+','+acc.State__c+','+acc.PostalCode__c+','+acc.Country__c +'"'); system.debug('active students'); //and Location__c // and Location__r.Name =:keyword } } List<Student__c> lstInActiveStudent=[select Apt_No__c,Street_Address__c, City__c, State__c,PostalCode__c, Country__c from Student__c where City__c!=null and Status__c='Inactive' and Location__c=:ajay]; if(lstInActiveStudent!=null && lstInActiveStudent.size()>0){ for(Student__c acc:lstInActiveStudent){ listOfInActiveAddresses.add('"'+acc.Street_Address__c+','+acc.City__c+','+acc.State__c+','+acc.PostalCode__c+','+acc.Country__c +'"'); system.debug('active students'); // and Location__r.Name =:keyword } } return null; } }
Please let me kow if you got any solution to this problem. thank you.
https://stackoverflow.com/questions/14014074/google-maps-api-over-query-limit-per-second-limit