Hi Salesforce community,
I've been going through the visual force workbook and I've encountered an error with the findNearbyWearHouses app.
I've copied all the code at the end of the tutorial, but the page does not render, I simply get a blank page.
I've gone over to see if all the curly brackets match and I went through the code line by line to see if it matches and it does.
This feels mildly discouraging, but it's probably something stupid and non-deterministic of my coding skills
Here's my code, could anyone spot an error?
<apex:page sidebar="false" showheader="false"
standardController="Warehouse__c" recordSetVar="warehouses"
extensions="WarehouseUtils">
<apex:includeScript value="{!$Resource.googleMapsAPI}" />
<style>
html, body { height: 100%; }
.page-map, .ui-content, #map-canvas { width: 100%; height:100%; padding: 0; }
#map-canvas { height: min-height: 100%; }
</style>
<script>
function initialize() {
var lat, lon;
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position){
lat = position.coords.latitude;
lon = position.coords.longitude;
Visualforce.remoting.Manager.invokeAction(
'{!$RemoteAction.WarehouseUtils.findNearbyWarehouses}',
lat, lon,
function(result, event){
if (event.status) {
console.log(result);
createMap(lat, lon, result);
} else if (event.type === 'exception') {
//exception case code
} else {
}
},
{escape: true}
);
});
} else {
lat = 37.77493;
lon = -122.419416;
var result = [];
createMap(lat, lon, result);
}
}
function createMap(lat, lon, warehouses){
var currentPosition = new google.maps.LatLng(lat,lon);
var mapDiv = document.getElementById('map-canvas');
var map = new google.maps.Map(mapDiv, {
center: currentPosition,
zoom: 13,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var positionMarker = new google.maps.Marker({
map: map,
position: currentPosition,
icon: 'https://maps.google.com/mapfiles/ms/micons/green.png'
});
var mapBoundary = new google.maps.LatLngBounds();
mapBoundary.extend(currentPosition);
var warehouse;
for(var i=0; i<warehouses.length ; i++) {
warehouse = warehouses[i];
console.log(warehouses[i]);
setupMarker();
}
map.fitBounds(mapBoundary);
function setupMarker(){
var warehouseNavUrl;
try{
if(sforce.one){
warehouseNavUrl = 'javascript:sforce.one.navigateToSObject(\'' + warehouse.Id + '\')';
}
} catch(err) {
console.log(err);
warehouseNavUrl = '\\' + warehouse.Id;
}
var warehouseDetails =
'<a href="' + warehouseNavUrl + '">' +
warehouse.Name + '</a><br/>' +
warehouse.Street_Address__c + '<br/>' +
warehouse.City__c + '<br/>' +
warehouse.Phone__c;
var infowindow = new google.maps.InfoWindow({
content: warehouseDetails
});
var marker = new google.maps.Marker({
map: map,
position: new google.maps.LatLng(
warehouse.Location__Latitude__s,
warehouse.Location__Longitude__s)
});
mapBoundary.extend(marker.getPosition());
google.maps.event.addListener(marker, 'click', function(){
infowindow.open(map, marker);
});
}
}
// Fire the initialize function when the window loads
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<body style="font-family: Arial; border: 0 none;">
<div id="map-canvas"></div>
</body>
</apex:page>