Map of google maps turns gray, but when I change the browser zoom back, what should I do?

3

So, guys, I have 2 parts of the system where I work, where I use a map to show the address of the property or person. But that in the property works perfectly, but in person (q has the same codes) I have to zoom in on the browser that looks perfect again .... Does anyone know what can happen to this? Thanks!

One important thing I forgot to mention, it's in a partialView, so it's being placed there while the page loads ...

Remembering that this code already existed in the system I just solved some problems.

    -edit-3
    var map;
    var marker;
    /* ============================ MÉTODOS PARA O MAPA ============================ */
    function initializeMap() {
        latlng = new google.maps.LatLng(-15.796892001990338, -47.890573438861864);
        var myOptions = { 
            zoom: 14, 
            center: latlng, 
            mapTypeId: google.maps.MapTypeId.ROADMAP 
        };

        map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
        createMarker(latlng);

        var position = undefined;
        <% var endereco = this.Model.Endereco;
        if (endereco.Latitude.HasValue && endereco.Longitude.HasValue)
        {%>
               position = new google.maps.LatLng(
               <%: endereco.Latitude.GetValueOrDefault().ToString(System.Globalization.CultureInfo.InvariantCulture) %>, 
               <%: endereco.Longitude.GetValueOrDefault().ToString(System.Globalization.CultureInfo.InvariantCulture) %>);
               changeMarkerPosition(position);
               <%}
        else
        {%>
        changeMarkerPositionByAddress(getEnderecoCompleto());
        <%}%>

        infowindow = new google.maps.InfoWindow();

        $("#mapaContato").css('display','block');
    }

    function createMarker(position) {
        map.setCenter(position);
        markerOptions = {
            draggable: true,
            map: map,
            position: position,
            visible: true
        };
        marker = new google.maps.Marker(markerOptions);
        google.maps.event.addListener(marker, 'position_changed', OnMarkerPositionChanged);
    }

    function changeMarkerPosition(position) {
        marker.setPosition(position);
        map.setCenter(position);
    }

    function changeMarkerPositionByAddress(address) {
        geocoder = new google.maps.Geocoder();
        geocoder.geocode({ 'address': address, region: "BR" }, function (results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                local = results[0].geometry.location;
                changeMarkerPosition(local);
            } else if (status == google.maps.GeocoderStatus.ZERO_RESULTS) {
                alert("Não foi localizada uma coordenada geográfica para este endereço.\nFavor localizar o ponto manualmente no mapa.");
            } else {
                alert("A busca no mapa resultou em um erro inesperado.\nErro: " + status);
            }
        });
    }

    function OnMarkerPositionChanged() {
        var local = marker.getPosition();
        updateMarkerPosition(local);
    }

    function updateMarkerPosition(latLng) {
        $("#Endereco_Latitude").val(doubleToString(latLng.lat()));
        $("#Endereco_Longitude").val(doubleToString(latLng.lng()));
    }

    function doubleToString(value) {
        <% var culture = System.Globalization.CultureInfo.CurrentCulture;
        var formatInfo = (System.Globalization.NumberFormatInfo)culture.GetFormat(typeof(System.Globalization.NumberFormatInfo));
        if (formatInfo.NumberDecimalSeparator == "," && formatInfo.NumberGroupSeparator == ".")
        {%>
               return value.toString().replace(".", ",");
               <%}
        else
        {%>
        return value.toString();
        <%}
    %>
    }
    
asked by anonymous 19.07.2016 / 07:02

1 answer

2

I solved the problem, in which case the map was being rendered inside a partial view. Then I put the method to initialize the map in the view that loads the partial view. And then when it started it rendered normally. Thanks Andre uses the answer helped me in this!

    
20.07.2016 / 05:55