Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Yahia Zakaria 2 posts 74 karma points
    Jan 24, 2016 @ 11:49
    Yahia Zakaria
    2

    Resizing Google Maps fix and adding click event

    Hi Dirk, for the resizing issue, you can use:

    google.maps.event.addListener(map, 'idle', function () {
                google.maps.event.trigger(map, 'resize');
            });
    

    this will draw the map again after the page is fully loaded.

    Also you can add the click event so it will be more easy to add the content

    google.maps.event.addListener(map, 'click', function (event) {
                placeMarker(event.latLng);
            });
    function placeMarker(location) {
    
            if (marker != null) {
                marker.setMap(null);
            }
    
            marker = new google.maps.Marker({
                map: map,
                position: location,
                draggable: true
            });
            marker.setMap(map);
    
            lookupPosition(location);
            addMarkerDragEndListener();
    
            map.setCenter(location);
            map.panTo(location);
        }
    
  • Amir Khan 1287 posts 2744 karma points
    Feb 03, 2016 @ 16:03
    Amir Khan
    0

    Hi Yahia, where in the controller do you advise adding these?

    Thanks!

    Amir

  • Yahia Zakaria 2 posts 74 karma points
    Feb 03, 2016 @ 16:17
    Yahia Zakaria
    0

    Hi Amir, you will add the function like "initializeMap" function. And for the listeners, you are going to add it in the "initializeMap" function.

  • Amir Khan 1287 posts 2744 karma points
    Feb 09, 2016 @ 14:57
    Amir Khan
    0

    So the position on click worked perfectly. The resize event doesn't seem to be firing though.

    I placed them both right after google.maps.event.addDomListener(resetBtn,'click',resetMap);

    Any ideas?

Please Sign in or register to post replies

Write your reply to:

Draft