views:

105

answers:

1

Hi there,

I'm trying to add multiple markers to my GWT-Map. If I do it with the geocoder, it works just fine... But I also get the values from a database, so I can place them via Lat Lng.

That's the code:

public static void markerSetzen(final double lat, final double lon) {
    /* Markeroptionen setzen */
    MarkerOptions markeroptions = MarkerOptions.newInstance();
    markeroptions.setBouncy(true);
    markeroptions.setBounceGravity(0.3);


    final Marker marker = new Marker(LatLng.newInstance(lat, lon),
            markeroptions);

    map.addOverlay(marker);
    marker.addMarkerClickHandler(new MarkerClickHandler() {

        @Override
        public void onClick(MarkerClickEvent event) {
            // popup- Fenster erstellen
            map.getInfoWindow().open(
                    LatLng.newInstance(lat, lon),
                    new InfoWindowContent(image + name + "<br>" + ort
                            + "<br>" + kategorie + "<br><br>"
                            + beschreibung + "<br>" + web));

        }
    });
}

The exception is always thrown at map.addOverlay(). I check the returned doubles from the db via syso and they're just fine...

I hope someone can help,

thanks in advance

EDIT: that is the code of the geocoder method, which does what I want:

public static void koordSuchen(final double lat, final double lon,
        final String ort, final String image, final String name,
        final String kategorie, final String beschreibung,
        final String web, final int zoomlevel) {
    // Geokodierung von Adressen herausbekommen
    Geocoder geocoder = new Geocoder();
    geocoder.getLatLng(ort, new LatLngCallback() {

        @Override
        public void onSuccess(LatLng point) {
            final LatLng ortKoord = LatLng.newInstance(lat, lon);
            // neuen Marker erstellen
            Marker marker = new Marker(ortKoord);
            // neues Marker- Overlay erstellen
            map.addOverlay(marker);
            // Marker Klickhandler erstellen (Bei klick auf Marker oeffnet
            // sich ein Popup)
            marker.addMarkerClickHandler(new MarkerClickHandler() {

                @Override
                public void onClick(MarkerClickEvent event) {
                    // popup- Fenster erstellen
                    map.getInfoWindow().open(
                            ortKoord,
                            new InfoWindowContent(image + name + "<br>"
                                    + ort + "<br>" + kategorie + "<br><br>"
                                    + beschreibung + "<br>" + web));

                }
            });
        }

        @Override
        public void onFailure() {
        }
    });
}
A: 

map.addOverlay() is the first instance of the variable map in your sample code. Are you sure map is initialized?

Paul Tomblin
Yes, it's initialized. I found out meanwhile, that if I have the above code in the onSuccess of the geocoder it works wonderful with the Lat Lng doubles from my db. Even though the geocoder will search for the string I gave to it and would return the LatLng object I could use (what I don't), I can draw the markers with the coordinates from the db.If I remove the geocoder, the markers can't be placed anymore and I'm back with my NullPointerException :/
Chris

related questions