I am currently trying to add some customer markers to a map. I can add a single marker to the map but when I move that same logic inside of an Apex:repeat I no longer have access to the map variable.
My Javascript:
<script type="text/javascript">
function initialize() {
var mapProp = {
center:new google.maps.LatLng(52.634092,-0.148315),
zoom:10,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
var map=new google.maps.Map(document.getElementById("googleMap"),mapProp);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
My VP page:
<apex:repeat value="{!Locations}" var="local" id="mapMarkers" >
<script type="text/javascript">
var lat = '{!Locations[0].Geolocation__Latitude__s}';
var lng = '{!Locations[0].Geolocation__Longitude__s}';
var marker=new google.maps.Marker({
position: new google.maps.LatLng(lat, lng)
});
marker.setMap(map);
</script>
</apex:repeat>
The !Locations list is in my controller and just pulls the latitude and longitude from my Tree__c object:
public List<Tree__c> getLocations() {
List<Tree__c> locations = Database.query('SELECT Geolocation__Latitude__s, Geolocation__Longitude__s FROM Tree__c WHERE Geolocation__Latitude__s !=null AND Geolocation__Longitude__s !=null ');
return locations;
}