function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Angela Mullen-Smith 20Angela Mullen-Smith 20 

Created a Visual force page to display Accounts on a Google map - markers not appearing on a visualforce page

I created a google map for a Custom Object and it works fine. I then decided to adapt it for my Accounts page - no erroors but Markers are not appearing on my Map

APEX CLASS 

global with sharing class AccountRemoter {
    @RemoteAction
    global static List<Account> findAll() {
    return [SELECT Id, Name, geoLocation__Latitude__s,  geoLocation__Longitude__s
    FROM Account];
    }
}

Visualforcepage

<apex:page sidebar="false" showheader="false" controller="AccountRemoter">
<head>
<style type="text/css">
  html { height: 100% }
  body { height: 100%; margin: 0; padding: 0 }
  #map-canvas { height: 100% }
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3&key=AIzaSyC3GwkxsiGHfc0y5sheupDf7QzKtbFI4jg&region=AU">
 
</script>
<script>
var map;
function initialize() {
    var mapOptions = {
        center: new google.maps.LatLng(-16.45789579, 145.3789838),
        zoom: 15
    };
    map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
    loadAccount();
}
function loadAccount() {
    Visualforce.remoting.Manager.invokeAction('{!$RemoteAction.AccountRemoter.findAll}',
        function(result, event){
            if (event.status) {
                for (var i=0; i<result.length; i++) {
                    var id = result[i].Id;
                    var name = result[i].Name;
                    var lat = result[i].geoLocation__Latitude__s;
                    var lng = result[i].geoLocation__Longitude__s;
                    addMarker(id, name, lat, lng);
                }
            } else {
                alert(event.message);
            }
        },
        {escape: true}
    );
}
function addMarker(id, name, lat, lng) {
    var marker = new google.maps.Marker({
            position: new google.maps.LatLng(lat, lng),
            map: map,
            title: name
    });
    google.maps.event.addListener(marker, 'click', function(event) {
        window.top.location = '/' + id;
    });
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
  <div id="map-canvas"/>
</body>
</apex:page>
bhanu_prakashbhanu_prakash
Hi Angela,
Mark as best answer, If it resloves !!
need to create  both fields geoLocation__Latitude__s and  geoLocation__Longitude__s in account objects.
modify you apex controller into extenstion , you cannot use standard controller and custom controller in same vf page
global with sharing class AccountRemoter {
    private final Account acct;
    public AccountRemoter(ApexPages.StandardController stdController) {
        this.acct = (Account) stdController.getRecord();
    }
    @RemoteAction

    global static List < Account > findAll() {
        return [SELECT Id, Name
            FROM Account
        ];
    }
}
Add code in vf page
<apex:page sidebar="false" showheader="false" extensions="AccountRemoter" standardController="Account" >
Mark as resloved if it helps :) :)
Thanks, 
Bhanu Prakash
visit ForceLearn.com​  (https://www.forcelearn.com)

 
Angela Mullen-Smith 20Angela Mullen-Smith 20
Hi @bhanu_prakash
My geolocation fields are already set up on my account object.
I made the amendments as suggested but I still only see the map with no markers
bhanu_prakashbhanu_prakash
Hi Angela,

add console. log to find whether values are entering into here or not 
addMarker(id, name, lat, lng);
console.log("id":+id);
console.log("name":+name);
console.log("lat":+lng);
 }
If you need to get vaues into that 
check these link  https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_maps_markers.htm