GWT Google Map Api V3 - Broken When Changed

It works great for me for the first time. But, if I changed something on the map or recreated, it broke.

Here is a screenshot of what it looks like. Here

Here is a screenshot after I changed the results to a page. Here

This is my code.

@UiField DivElement mapPanel;

private GoogleMap googleMap;

public void loadAllMarkers(final List<LatLng> markers)
{
    if(!markers.isEmpty())
    {
        final MapOptions options = MapOptions.create();
        options.setMapTypeId(MapTypeId.ROADMAP);

        googleMap = GoogleMap.create(mapPanel, options);

        final LatLngBounds latLngBounds = LatLngBounds.create();

        for(LatLng latLng : markers)
        {
        final MarkerOptions markerOptions = MarkerOptions.create();

        markerOptions.setPosition(latLng);
        markerOptions.setMap(googleMap);

        final Marker marker = Marker.create(markerOptions);
        latLngBounds.extend(marker.getPosition());

        }

        googleMap.setCenter(latLngBounds.getCenter());
        googleMap.fitBounds(latLngBounds);

    }
}

I call the loadAllMarkers () method whenever I need to load new results.

Can someone point out what I'm doing wrong here.

+4
source share
1 answer

This is similar to the following (which I pulled from the Google+ community - GWT Maps V3 API ):

Brandon DonnelsonMar 5, 2013

, , mapwidget.triggerResize() reset . , onAttach , , div , . . , .

googleMap.triggerResize() . , . , , !

"" :

   @Override
protected void onAttach() {
    super.onAttach();
    Timer timer = new Timer() {

        @Override
        public void run() {
            resize();
        }
    };
    timer.schedule(5);
}

/*
 * This method is called to fix the Map loading issue when opening
 * multiple instances of maps in different tabs
 * Triggers a resize event to be consumed by google api in order to resize view
 * after attach.
 *
 */
public void resize() {
    LatLng center = this.getCenter();
    MapHandlerRegistration.trigger(this, MapEventType.RESIZE);        
    this.setCenter(center);
}
+2

All Articles