Example usage for com.google.gwt.maps.client.base HasLatLng getLatitude

List of usage examples for com.google.gwt.maps.client.base HasLatLng getLatitude

Introduction

In this page you can find the example usage for com.google.gwt.maps.client.base HasLatLng getLatitude.

Prototype

public double getLatitude();

Source Link

Document

Returns the latitude in degrees.

Usage

From source file:com.google.mobile.trippy.web.client.presenter.MapPresenter.java

License:Apache License

/**
 * Calculate the bounds that best fits the specified points
 *///from   w  w w .  j  av a2  s .  c o m
public HasLatLngBounds getBounds(List<HasLatLng> points) {
    if (points != null && points.size() > 1) {
        HasLatLng pointZero = points.get(0);
        HasLatLng pointOne = points.get(1);
        double northEastLat = Math.max(pointZero.getLatitude(), pointOne.getLatitude());
        double northEastLng = Math.max(pointZero.getLongitude(), pointOne.getLongitude());
        double southWestLat = Math.min(pointZero.getLatitude(), pointOne.getLatitude());
        double southWestLng = Math.min(pointZero.getLongitude(), pointOne.getLongitude());

        for (int i = 2, n = points.size(); i < n; i++) {
            final HasLatLng point = points.get(i);
            final double lat = point.getLatitude();
            final double lng = point.getLongitude();
            if (lat > northEastLat) {
                northEastLat = lat;
            }
            if (lng > northEastLng) {
                northEastLng = lng;
            }
            if (lat < southWestLat) {
                southWestLat = lat;
            }
            if (lng < southWestLng) {
                southWestLng = lng;
            }
        }
        final HasLatLng northEast = display.newLatLng(northEastLat, northEastLng);
        final HasLatLng southWest = display.newLatLng(southWestLat, southWestLng);
        return display.newLatLngBounds(southWest, northEast);
    } else {
        return null;
    }
}

From source file:com.mashery.examples.api.client.HotwireExample.java

License:Open Source License

public HotwireExample(final PopupMapWidget mapWidget) {
    FlowPanel panel = new FlowPanel();

    panel.add(new HTML("<h1>Hotel Deals</h1>"));

    FormPanel form = new FormPanel();
    panel.add(form);//from   ww  w .j  a  v a  2 s . c om

    FlexTable entryGrid = new FlexTable();
    form.add(entryGrid);
    FlexTable.FlexCellFormatter formatter = (FlexCellFormatter) entryGrid.getCellFormatter();
    entryGrid.setWidget(0, 0, new Label("Destination:"));
    formatter.setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_RIGHT);

    FlowPanel destPanel = new FlowPanel();
    entryGrid.setWidget(0, 1, destPanel);
    formatter.setColSpan(0, 1, 5);

    final TextBox destText = new TextBox();
    destPanel.add(destText);
    destText.setWidth("220px");

    Anchor fromMapLink = new Anchor("<- from Map");
    fromMapLink.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            HasLatLng center = mapWidget.getMap().getCenter();
            destText.setText(center.getLatitude() + "," + center.getLongitude());
        }
    });

    destPanel.add(new InlineHTML("&nbsp;"));
    destPanel.add(fromMapLink);

    entryGrid.setWidget(1, 0, new Label("From:"));
    formatter.setHorizontalAlignment(1, 0, HasHorizontalAlignment.ALIGN_RIGHT);

    final TextBox startDateText = new TextBox();
    entryGrid.setWidget(1, 1, startDateText);
    startDateText.setWidth("100px");

    final PopupPanel startDatePanel = new PopupPanel(true);
    startDatePanel.setAutoHideOnHistoryEventsEnabled(true);

    final ToggleButton startDateButton = new ToggleButton(new Image("resources/img/date-picker.gif"));
    entryGrid.setWidget(1, 2, startDateButton);
    startDateButton.setPixelSize(16, 16);
    startDatePanel.addAutoHidePartner(startDateButton.getElement());
    startDateButton.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            startDatePanel.showRelativeTo(startDateButton);
        }
    });

    startDatePanel.addCloseHandler(new CloseHandler<PopupPanel>() {
        @Override
        public void onClose(CloseEvent<PopupPanel> event) {
            startDateButton.setDown(false);
        }
    });

    final DateTimeFormat dateFormat = DateTimeFormat.getFormat("MM/dd/yyyy");

    final DatePicker startDatePicker = new DatePicker();
    startDatePanel.setWidget(startDatePicker);
    startDatePicker.addValueChangeHandler(new ValueChangeHandler<Date>() {
        @Override
        public void onValueChange(ValueChangeEvent<Date> event) {
            startDateText.setText(dateFormat.format(event.getValue()));
            startDatePanel.hide();
        }
    });

    startDateText.addValueChangeHandler(new ValueChangeHandler<String>() {
        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            try {
                Date date = dateFormat.parse(event.getValue());
                startDatePicker.setValue(date);
            } catch (IllegalArgumentException e) {
                // ignore
            }
        }
    });

    Date date = new Date();
    startDatePicker.setValue(date, true);

    entryGrid.setWidget(1, 3, new Label("To:"));
    formatter.setHorizontalAlignment(1, 2, HasHorizontalAlignment.ALIGN_RIGHT);

    final TextBox endDateText = new TextBox();
    entryGrid.setWidget(1, 4, endDateText);
    endDateText.setWidth("100px");

    final PopupPanel endDatePanel = new PopupPanel(true);
    endDatePanel.setAutoHideOnHistoryEventsEnabled(true);

    final ToggleButton endDateButton = new ToggleButton(new Image("resources/img/date-picker.gif"));
    entryGrid.setWidget(1, 5, endDateButton);
    endDateButton.setPixelSize(16, 16);
    endDatePanel.addAutoHidePartner(endDateButton.getElement());
    endDateButton.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            endDatePanel.showRelativeTo(endDateButton);
        }
    });

    endDatePanel.addCloseHandler(new CloseHandler<PopupPanel>() {
        @Override
        public void onClose(CloseEvent<PopupPanel> event) {
            endDateButton.setDown(false);
        }
    });

    final DatePicker endDatePicker = new DatePicker();
    endDatePanel.setWidget(endDatePicker);
    endDatePicker.addValueChangeHandler(new ValueChangeHandler<Date>() {
        @Override
        public void onValueChange(ValueChangeEvent<Date> event) {
            endDateText.setText(dateFormat.format(event.getValue()));
            endDatePanel.hide();
        }
    });

    endDateText.addValueChangeHandler(new ValueChangeHandler<String>() {
        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            try {
                Date date = dateFormat.parse(event.getValue());
                endDatePicker.setValue(date);
            } catch (IllegalArgumentException e) {
                // ignore
            }
        }
    });

    date = CalendarUtil.copyDate(date);
    CalendarUtil.addDaysToDate(date, 1);
    endDatePicker.setValue(date, true);

    SubmitButton submitButton = new SubmitButton("Search");
    entryGrid.setWidget(2, 0, submitButton);
    formatter.setColSpan(2, 0, 6);
    formatter.setHorizontalAlignment(2, 0, HasHorizontalAlignment.ALIGN_RIGHT);

    final HotelDealsTable table = new HotelDealsTable(10);
    panel.add(table);
    table.setWidth("500px");

    form.addSubmitHandler(new FormPanel.SubmitHandler() {
        @Override
        public void onSubmit(SubmitEvent event) {
            String dest = destText.getValue().trim();
            String start = startDateText.getValue().trim();
            String end = endDateText.getValue().trim();
            table.loadData(dest.length() == 0 ? null : dest, start.length() == 0 ? null : start,
                    end.length() == 0 ? null : end);
            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;

            MarkerOptions opt = new MarkerOptions();
            opt.setTitle(selectedResult.getHeadline());
            LatLng latLng = new LatLng(selectedResult.getNeighborhoodLatitude(),
                    selectedResult.getNeighborhoodLongitude());
            opt.setPosition(latLng);
            opt.setClickable(true);
            opt.setVisible(true);
            mapWidget.show(new Marker(opt));

        }
    });

    mapWidget.addAutoHidePartner(mapLink.getElement());

    linkPanel.add(new InlineHTML("&nbsp;|&nbsp;"));
    linkPanel.add(visitLink = new Anchor("Visit", "#"));

    initWidget(new ScrollPanel(panel));
}

From source file:com.mashery.examples.api.client.PopupMapWidget.java

License:Open Source License

public void show(HasMarker marker) {
    HasLatLng position = marker.getPosition();
    double lat = position == null ? 0d : position.getLatitude();
    double lng = position == null ? 0d : position.getLongitude();
    MarkerKey key = new MarkerKey(marker.getTitle(), lat, lng);
    if (!markers.containsKey(key)) {
        marker.setMap(mapWidget.getMap());
        markers.put(key, marker);/*www.  j  a v  a 2 s  . c  o m*/
    }

    show(position == null ? new LatLng(lat, lng) : position);
}

From source file:com.mashery.examples.api.client.WeatherBugExample.java

License:Open Source License

private void fetchWeather() {
    table.setText(0, 0, "Loading...");
    ForecastServiceAsync svc = GWT.create(ForecastService.class);
    mapWidget.show();//from  w  w w.j  av  a  2s  . c  o  m
    HasLatLng latLng = mapWidget.getMap().getCenter();
    svc.getForecast(latLng.getLatitude(), latLng.getLongitude(), new AsyncCallback<Weather>() {

        @Override
        public void onSuccess(Weather weather) {
            table.setText(0, 0, "");
            mapWidget.hide();

            Forecasts forecastWrapper = weather.getForecasts();
            if (forecastWrapper == null)
                return;

            Location location = forecastWrapper.getLocation();
            if (location != null) {
                StringBuilder buf = new StringBuilder("<strong>");
                if (location.getCity() != null)
                    buf.append(location.getCity());

                if (location.getState() != null) {
                    if (buf.length() > 0)
                        buf.append(", ");

                    buf.append(location.getState());
                }

                if (location.getZip() != null) {
                    if (buf.length() > 0)
                        buf.append(' ');

                    buf.append(location.getZip());
                }

                if (location.getCountry() != null) {
                    if (buf.length() > 0)
                        buf.append(", ");

                    buf.append(location.getCountry());
                }

                table.setHTML(0, 0, buf.append("</strong>").toString());
            }

            Forecast[] forecasts = forecastWrapper.getForecasts();
            if (forecasts != null) {
                for (int i = 0; i < forecasts.length; ++i) {
                    table.setText(i + 1, 0, forecasts[i].getDescription());
                    table.setWidget(i + 1, 1, new Image(forecasts[i].getImage()));
                    table.setHTML(i + 1, 2, forecasts[i].getPrediction());
                    table.setHTML(i + 1, 3, forecasts[i].getHigh() + "&deg;F");
                    table.setHTML(i + 1, 4, forecasts[i].getLow() + "&deg;F");
                }
            }
        }

        @Override
        public void onFailure(Throwable caught) {
            table.setText(0, 0, "");
            mapWidget.hide();
            Window.alert(caught.getLocalizedMessage());
        }
    });
}