java - Getting Location details from Google Map in gwt -
i need perform tasks google map, 1. first need user able place 1 marker 2. retrieve city , other details such street address
does know this?
i wrote minimal example show how achieve you're looking for:
public void onmoduleload() { rootpanel.get().add(new googlemaps()); } private class googlemaps extends composite { private mapwidget fmap; private geocoder fcoder; private marker fmarker; public googlemaps() { fmap = new mapwidget(latlng.newinstance(47.0559084, 8.3114878), 6); fmap.setsize("300px", "300px"); fcoder = new geocoder(); markeroptions options = markeroptions.newinstance(); options.setdraggable(true); fmarker = new marker(latlng.newinstance(47.0559084, 8.3114878), options); fmap.addoverlay(fmarker); fmarker.setvisible(false); addhandlers(); initwidget(fmap); } private void addhandlers() { fmap.addmapdoubleclickhandler(new mapdoubleclickhandler() { @override public void ondoubleclick(mapdoubleclickevent event) { if (event.getlatlng() != null) { performreverselookup(event.getlatlng()); } } }); fmarker.addmarkerdragendhandler(new markerdragendhandler() { @override public void ondragend(markerdragendevent event) { latlng point = event.getsender().getlatlng(); if (point != null) { performreverselookup(point); } } }); } private void performreverselookup(final latlng point) { fcoder.getlocations(point, new locationcallback() { @override public void onsuccess(jsarray<placemark> locations) { if (locations.length() > 0) { latlng point = locations.get(0).getpoint(); fmarker.setlatlng(point); fmarker.setvisible(true); fmap.getinfowindow().open(point, new infowindowcontent(locations.get(0).getaddress())); } } @override public void onfailure(int statuscode) {} }); } }
to first point: create 1 instance of marker
, update latlng
upon user interaction (done in performreverselookup()
).
your second question: after performing reverse lookup can placemark
object out of locations
array , retrieve details address.
Comments
Post a Comment