I'm trying to make a webpage using asp.net, and need to use a loop to display several markers on a google map. The error description says that the google namespace cannot be found within the loop, while it works fine for the rest of the function. Does anyone know how to fix this? What I expected from this code is a map with markers at 46, -80; 47, -79; and 48, -78. Here's my code

    <script src="http://maps.googleapis.com/maps/api/js?key=MyKey"></script>
        function initialize() {
            var mapProp = {
                center: new google.maps.LatLng(44, -80), //this google.maps call is fine
                zoom: 5,
                mapTypeId: google.maps.MapTypeId.ROADMAP //this one works too
            var ClownMap = new google.maps.Map(document.getElementById("googleMap"), mapProp);

                @for (var i=1; i < 4; i++){
                            var latitude = 45+i;
                            var longitude = -81+i;
                            var markerPosition = new google.maps.LatLng(latitude, longitude); //This line gives an error
                            var marker = new google.maps.Marker({ position: markerPosition}); } //Error here too
        google.maps.event.addDomListener(window, 'load', initialize);

    <div id="googleMap" style="width:960px;height:600px;"></div>

Related posts

Recent Viewed