Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grey area in Google maps

I have implemented Google maps in my app (in a modal), however as you can see on the images below there is a grey area that I of course want to get rid of. It is possible to move the map so that the grey area disappears, but that shouldn't be needed.

Thing is that the map is shown inside a modal box, which contains of a lot of content that's dynamically created when the button for showing the modal is clicked. It seems that the problem could be that the map content isn't fully loaded before the modal is loaded, but I'm not sure...

html:

    ...
  <div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-header">
      <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
      <h3 id="myModalLabel">Test</h3>
    </div>
    <div id="modal-left" class="modal-body left"></div>
    <div class="modal-body right">
      <div id="map"></div>
    </div>
  </div>
    ...

js:

    function initializeMap(latitude, longitude) {
        var place = new google.maps.LatLng (latitude, longitude);

        var myOptions = {
            zoom: 10,
            center: place,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        }

        var map = new google.maps.Map(document.getElementById("map"), myOptions);

        var marker = new google.maps.Marker({
            position: place,
            map: map,
            title: ""
        });
    };

    $('.modal-btn').click(function(){
        var producerId = $(this).attr('id');

        GetProducer(producerId, function(data) {  // <--- data retrieved through ajax
            initializeMap(data.latitude, data.longitude);

            var titel = data.name;

            var content = "<p><img class='modal-img' src='" + data.imgurl + "' /></p>" +
                        "<p>" + data.name + ", " + data.address + "<br/>" +
                        data.zipcode + " " + data.town + "</p>" +
                        "<p><a href='" + data.url + "' >" + data.url + "</a></p>";

            $('#myModalLabel').html(titel);
            $('#modal-left').html(content);
        });
    });

Image 1:

Image 2:

like image 998
holyredbeard Avatar asked Dec 16 '12 13:12

holyredbeard


People also ask

What is grey area on Google Maps?

Sometimes when you scroll across a Google Map screen you'll see blocks of grey. Usually this occurs when the map is set to satellite view and the application struggles to load the data fast enough. However, sometimes this phenomenon occurs in map view if Google doesn't have access to the right data.

What does grey on a map mean?

On some maps, post offices, churches, city halls, and other landmark buildings are shown within the tinted area. The first features usually noticed on a topographic map are the area features, such as vegetation (green), water (blue), and densely built-up areas (gray or red).

What does the shaded area on Google map show?

As you explore the new map, you'll notice areas shaded in orange representing “areas of interest”—places where there's a lot of activities and things to do. To find an “area of interest” just open Google Maps and look around you.

Why did the location turn grey?

All replies. the greyed out location is because the location is an old or outdated location and is not being refeshed anymore. this is because the person who shared the location with you either turned off their phone or manually stopped sharing their location with you.


2 Answers

The usual reason why this is happening is that the size of the map is changed after the map has been initialized. If you for some reason change the size of the div with id="map" you need to trigger the "resize" event

google.maps.event.trigger(map, 'resize');

You could just try to trigger the event in your javascript console and see if it helps.

Please note that this answer is a guess since there is not really anything in the question to work with, so please let me know if it does not help.

like image 155
Nils Avatar answered Sep 19 '22 06:09

Nils


Put google.maps.event.trigger(map, "resize"); in a setTimeout function so that it fires AFTER the event is triggered.

like image 35
tanwill Avatar answered Sep 22 '22 06:09

tanwill