List of usage examples for com.google.gwt.maps.client.geocoder HasGeocoderResult getAddressComponents
public List<HasAddressComponent> getAddressComponents();
From source file:com.google.mobile.trippy.web.client.presenter.CreateNewTripPresenter.java
License:Apache License
/** * Registering the pop up click handlers. *//*from ww w . ja v a 2s . c o m*/ @SuppressWarnings("deprecation") boolean registerSuggestedHandlers(final List<HasGeocoderResult> responses) { final List<HasGeocoderResult> validLocations = new ArrayList<HasGeocoderResult>(); for (final HasGeocoderResult suggestedTrip : responses) { final HasLatLngBounds bounds = suggestedTrip.getGeometry().getBounds(); final String address = suggestedTrip.getAddressComponents().get(0).getLongName(); if (bounds != null && address != null) { validLocations.add(suggestedTrip); } } final List<String> suggestedTripList = new ArrayList<String>(); for (HasGeocoderResult suggestedTrip : validLocations) { suggestedTripList.add(suggestedTrip.getFormattedAddress()); } if (!suggestedTripList.isEmpty()) { display.addSuggestedTripList(suggestedTripList); List<HasClickHandlers> suggestedHandlers = display.getSuggestedTripList(); for (int i = 0; i < validLocations.size(); i++) { final HasGeocoderResult suggestedTrip = validLocations.get(i); final HasLatLngBounds bounds = suggestedTrip.getGeometry().getBounds(); final String address = suggestedTrip.getAddressComponents().get(0).getLongName(); final String location = suggestedTrip.getFormattedAddress(); suggestedHandlers.get(i).addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { addTripToDb(location, address, bounds); } }); } return true; } return false; }
From source file:com.mashery.examples.api.client.ActiveExample.java
License:Open Source License
public ActiveExample(final PopupMapWidget mapWidget) { FlowPanel panel = new FlowPanel(); panel.add(new HTML("<h1>Search</h1>")); FormPanel form = new FormPanel(); panel.add(form);/*from w w w . ja v a2 s .c o m*/ FlexTable entryGrid = new FlexTable(); form.add(entryGrid); FlexTable.FlexCellFormatter formatter = (FlexCellFormatter) entryGrid.getCellFormatter(); entryGrid.setWidget(0, 0, new Label("Keywords:")); formatter.setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_RIGHT); final TextBox keywordsText = new TextBox(); entryGrid.setWidget(0, 1, keywordsText); keywordsText.setWidth("200px"); entryGrid.setWidget(1, 0, new Label("Location:")); formatter.setHorizontalAlignment(1, 0, HasHorizontalAlignment.ALIGN_RIGHT); final TextBox locationText = new TextBox(); entryGrid.setWidget(1, 1, locationText); locationText.setWidth("200px"); Anchor fromMapLink = new Anchor("<- from Map"); final Geocoder geocoder = new Geocoder(); fromMapLink.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { mapWidget.show(); HasLatLng center = mapWidget.getMap().getCenter(); GeocoderRequest request = new GeocoderRequest(); request.setLatLng(center); geocoder.geocode(request, new GeocoderCallback() { @Override public void callback(List<HasGeocoderResult> responses, String status) { if (responses != null) { String postalCode = null; String country = null; RESULTS: for (HasGeocoderResult result : responses) { if (result.getTypes().contains("postal_code")) { for (HasAddressComponent addr : result.getAddressComponents()) { if (postalCode == null && addr.getTypes().contains("postal_code")) postalCode = addr.getLongName(); if (country == null && addr.getTypes().contains("country")) country = addr.getLongName(); if (postalCode != null && country != null) break RESULTS; } } } if (postalCode != null) { if (country == null) locationText.setText(postalCode); else locationText.setText(postalCode + ", " + country); } } } }); } }); entryGrid.setWidget(1, 2, fromMapLink); SubmitButton submitButton = new SubmitButton("Search"); entryGrid.setWidget(2, 0, submitButton); formatter.setColSpan(2, 0, 3); formatter.setHorizontalAlignment(2, 0, HasHorizontalAlignment.ALIGN_RIGHT); final SearchResultsTable table = new SearchResultsTable(10); panel.add(table); table.setWidth("500px"); form.addSubmitHandler(new FormPanel.SubmitHandler() { @Override public void onSubmit(SubmitEvent event) { String keywords = keywordsText.getValue().trim(); String location = locationText.getValue().trim(); table.loadData(keywords.length() == 0 ? null : keywords, location.length() == 0 ? null : location); event.cancel(); } }); infoPanel = new PopupPanel(true); infoPanel.setAutoHideOnHistoryEventsEnabled(true); infoGrid = new FlexTable(); infoPanel.setWidget(infoGrid); FlowPanel linkPanel = new FlowPanel(); infoGrid.setWidget(3, 0, linkPanel); Anchor mapLink = new Anchor("Map", "#"); linkPanel.add(mapLink); mapLink.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { event.preventDefault(); if (selectedResult == null) return; Meta meta = selectedResult.getMeta(); if (meta == null) { Window.alert("No location available."); return; } MarkerOptions opt = new MarkerOptions(); if (meta.getAssetName() != null) opt.setTitle(meta.getAssetName().trim()); opt.setPosition(new LatLng(meta.getLatitude(), meta.getLongitude())); opt.setClickable(true); opt.setVisible(true); mapWidget.show(new Marker(opt)); } }); mapWidget.addAutoHidePartner(mapLink.getElement()); linkPanel.add(new InlineHTML(" | ")); linkPanel.add(visitLink = new Anchor("Visit", "#")); ((FlexTable.FlexCellFormatter) infoGrid.getCellFormatter()).setColSpan(1, 0, 2); ((FlexTable.FlexCellFormatter) infoGrid.getCellFormatter()).setColSpan(2, 0, 2); ((FlexTable.FlexCellFormatter) infoGrid.getCellFormatter()).setColSpan(3, 0, 2); initWidget(new ScrollPanel(panel)); }