Can't place Marker in GWT Maps with Lat & Lng - Null Pointer Exception in map.addOverlay(Marker)
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() {
}
});
}
map.addOverlay()
is the first instance of the variable map
in your sample code. Are you sure map
is initialized?
精彩评论