Click here to Skip to main content
15,887,477 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I'm trying to add locations into google map marker with model data,but map doesn't load and prompt me to kill page, where as if i put 40 static locations to a marker, it loads well, how do i load marker values with model data below is my code
JavaScript
<pre> var map = new google.maps.Map(document.getElementById('googleMap'), {
        zoom: 5,
        center: new google.maps.LatLng(40.4931300000, -79.8631100000),
        mapTypeId: google.maps.MapTypeId.ROADMAP
    });

    var infowindow = new google.maps.InfoWindow();

    var marker, i;
    var locations = [];
   
    @for(int i = 0; i < Model.pallet.Lattitudes.Count; i++)
    {
        if (Model.pallet.Lattitudes[i] != null) {
        @:locations.push(new google.maps.LatLng('@Model.pallet.Lattitudes[i]', '@Model.pallet.Longitudes[i]'));
    }
    }
    for (i = 0; i < locations.length; i++) {
        marker = new google.maps.Marker({
            position: locations[i],
        });
        marker.setMap(map);
        google.maps.event.addListener(marker, 'click', (function (marker, i) {
            return function () {
                infowindow.setContent(locations[i][0]);
                infowindow.open(map, marker);
            }
        })(marker, i));
    }


What I have tried:

i tried putting 40 hard cocded location values into array and loads well ,but with model data it doesn't work
Posted
Updated 2-Aug-17 21:59pm

1 solution

We don't know what's in your model, so we can't find out; only you can.

Try to take a look at the source code of your page, and look what the JavaScript code is that your view generated. If something is wrong with that, find out where this comes from - you can use your debugger if necessary.
 
Share this answer
 
Comments
Member 12677894 3-Aug-17 4:08am    
model has proper location values, i checked with debugger
Thomas Daniels 3-Aug-17 4:31am    
So the resulting page looks exactly like when you hard-code the values?
Member 12677894 3-Aug-17 5:43am    
it doesnt push values into array
Thomas Daniels 3-Aug-17 5:52am    
Can you share the resulting JavaScript code, generated by the view?
Member 12677894 3-Aug-17 8:28am    
it'll be empty

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900