def __init__(self): DockPanel.__init__(self) self.setSize('100%', '100%') self.geocoder = Geocoder() # widgets topPanel = HorizontalPanel() self.add(topPanel, DockPanel.NORTH) self.address = TextBox() self.address.setText("Sydney, NSW") self.address.addChangeListener(self.codeAddress) topPanel.add(self.address) button = Button("Geocode") button.addClickListener(self.codeAddress) topPanel.add(button) # now, the map mapPanel = SimplePanel() mapPanel.setSize('600', '400') self.add(mapPanel, DockPanel.CENTER) options = MapOptions(zoom=8, center=LatLng(-34.397, 150.644), mapTypeId=MapTypeId.ROADMAP) self.map = Map(mapPanel.getElement(), options)
class GeocodingSimple(DockPanel): def __init__(self): DockPanel.__init__(self) self.setSize('100%', '100%') self.geocoder = Geocoder() # widgets topPanel = HorizontalPanel() self.add(topPanel, DockPanel.NORTH) self.address = TextBox() self.address.setText("Sydney, NSW") self.address.addChangeListener(self.codeAddress) topPanel.add(self.address) button = Button("Geocode") button.addClickListener(self.codeAddress) topPanel.add(button) # now, the map mapPanel = SimplePanel() mapPanel.setSize('600', '400') self.add(mapPanel, DockPanel.CENTER) options = MapOptions(zoom=8, center=LatLng(-34.397, 150.644), mapTypeId=MapTypeId.ROADMAP) self.map = Map(mapPanel.getElement(), options) def codeAddress(self): address = self.address.getText() print "codeAddress ", address if self.geocoder: request = GeocoderRequest(address=address) self.geocoder.geocode(request, self.geocodeResult) def geocodeResult(self, results, status): print "geocodeResult" if status == GeocoderStatus.OK: for res in results: print res.formatted_address print res.geometry.location.lat() print res.geometry.location.lng() for compo in res.address_components: print "- " + compo.short_name print "" self.map.setCenter(results[0].geometry.location) marker = Marker( MarkerOptions(map=self.map, position=results[0].geometry.location)) else: Window.alert( "Geocode was not successful for the following reason: " + status)
class GeocodingSimple(DockPanel): def __init__(self): DockPanel.__init__(self) self.setSize('100%', '100%') self.geocoder = Geocoder() # widgets topPanel = HorizontalPanel() self.add(topPanel, DockPanel.NORTH) self.address = TextBox() self.address.setText("Sydney, NSW") self.address.addChangeListener(self.codeAddress) topPanel.add(self.address) button = Button("Geocode") button.addClickListener(self.codeAddress) topPanel.add(button) # now, the map mapPanel = SimplePanel() mapPanel.setSize('600', '400') self.add(mapPanel, DockPanel.CENTER) options = MapOptions(zoom=8, center=LatLng(-34.397, 150.644), mapTypeId=MapTypeId.ROADMAP) self.map = Map(mapPanel.getElement(), options) def codeAddress(self): address = self.address.getText() print "codeAddress ", address if self.geocoder: request = GeocoderRequest(address=address) self.geocoder.geocode(request, self.geocodeResult) def geocodeResult(self, results, status): print "geocodeResult" if status == GeocoderStatus.OK: for res in results: print res.formatted_address print res.geometry.location.lat() print res.geometry.location.lng() for compo in res.address_components: print "- " + compo.short_name print "" self.map.setCenter(results[0].geometry.location) marker = Marker(MarkerOptions(map=self.map, position=results[0].geometry.location)) else: Window.alert( "Geocode was not successful for the following reason: " + status)