You need to sign in to do that
Don't have an account?
Angela 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®ion=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>
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®ion=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>
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 Add code in vf page Mark as resloved if it helps :) :)
Thanks,
Bhanu Prakash
visit ForceLearn.com (https://www.forcelearn.com)
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
add console. log to find whether values are entering into here or not 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