You need to sign in to do that
Don't have an account?
Janno Rip
Adding Info Windows to Markers - Customized
Hello developers,
I found the following article about "Adding Info Windows to Markers (https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_maps_info_windows.htm)" - basically displaying Salesforce data in GoogleMaps.
After a bit of trial and error I have created an apex class and a visualforce page that shows me customers close to the 'current account'
Now I want to top that with "Adding Info Windows to Markers" - Is this possible? Can I display here data of the Account/Marker that got clicked?
Here is my apex class:
/* https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_maps_example.htm */ public class FindNearbyController { public List<Map<String,Double>> locations { get; private set; } public Account currentAccount {get;set;} public FindNearbyController(ApexPages.StandardController stdController) { currentAccount = [SELECT ID, Geolocation__c FROM Account WHERE ID =: stdController.getID()]; } public String currentPosition { get { if (String.isBlank(currentPosition)) { currentPosition = currentAccount.Geolocation__c; } return currentPosition; } set; } public Boolean resultsAvailable { get { if(locations == Null) { return false; } return true; } } public PageReference findNearby() { String lat, lon; // FRAGILE: You'll want a better lat/long parsing routine // Format: "<latitude>,<longitude>" (must have comma, but only one comma) List<String> latlon = currentPosition.split(','); lat = latlon[0].trim(); lon = latlon[1].trim(); // SOQL query to get the nearest warehouses String queryString = 'SELECT Id, Name,LocateCity__longitude__s, LocateCity__latitude__s ' + 'FROM Account ' + 'WHERE DISTANCE(LocateCity__c, GEOLOCATION('+lat+','+lon+'), \'mi\') < 20 and Kundenstatus_Direktvertrieb__c = \'Bestandskunde\' ' + 'ORDER BY DISTANCE(LocateCity__c, GEOLOCATION('+lat+','+lon+'), \'mi\') ' + 'LIMIT 10'; // Run the query List <Account> warehouses = database.Query(queryString); if(0 < warehouses.size()) { // Convert to locations that can be mapped locations = new List<Map<String,Double>>(); for (Account wh : warehouses) { locations.add( new Map<String,Double>{ 'latitude' => wh.LocateCity__latitude__s, 'longitude' => wh.LocateCity__longitude__s } ); } } else { System.debug('No results. Query: ' + queryString); } return null; } }
Here the visualforce page:
<apex:page standardcontroller="Account" extensions="FindNearbyController" docType="html-5.0" > <apex:pageBlock > <!-- Form field to send currentPosition in request. You can make it an <apex:inputHidden> field to hide it. --> <apex:pageBlockSection > <apex:form > <apex:outputLabel for="currentPosition">Bestandskunden in der Nähe</apex:outputLabel> <apex:input size="30" html-placeholder="Attempting to obtain your position..." id="currentPosition" styleClass="currentPosition" value="{!currentPosition}" /> <apex:commandButton action="{!findNearby}" value="Go!"/> </apex:form> </apex:pageBlockSection> <!-- Map of the results --> <apex:pageBlockSection rendered="{!resultsAvailable}" title="Locations"> <apex:map width="600px" height="400px" mapType="roadmap"> <apex:repeat value="{!locations}" var="pos"> <apex:mapMarker position="{!pos}"/> </apex:repeat> </apex:map> </apex:pageBlockSection> </apex:pageBlock> </apex:page>
I suspect the below blog might help you check it once,
https://salesforce.stackexchange.com/questions/76708/google-maps-how-do-i-add-info-window-to-marker
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks.
thank you for your reply. Unfortunetaly I am not quite sure on how this would help me. It refers to another link I already found: https://releasenotes.docs.salesforce.com/en-us/summer15/release-notes/rn_vf_maps_enhancements_info_windows.htm
But I am having trouble to adapt this solution to my code since my records are stored in a list and I do not how to access the values / fields in ther. vs. Error: Unknown property 'pos.Name'