Example usage for com.google.gwt.maps.client.overlay Marker Marker

List of usage examples for com.google.gwt.maps.client.overlay Marker Marker

Introduction

In this page you can find the example usage for com.google.gwt.maps.client.overlay Marker Marker.

Prototype

protected Marker(JavaScriptObject jsoPeer) 

Source Link

Document

Create this marker from an existing JavaScriptObject instance.

Usage

From source file:com.apress.progwt.client.map.CollegeMapApp.java

License:Apache License

public CollegeMapApp(int pageID) {
    super(pageID);

    try {/*from   w  ww. j  ava 2 s  .c om*/
        Log.debug("In CollegeBound");
        double latitude = Double.parseDouble(getParam("latitude"));

        double longitude = Double.parseDouble(getParam("longitude"));

        LatLng collegeCenter = new LatLng(latitude, longitude);

        if (latitude == -1 && longitude == -1) {
            map = new MapWidget();
        } else {
            map = new MapWidget(collegeCenter, DEFAULT_ZOOM);
        }

        map.setSize("300px", "250px");

        map.addControl(new SmallMapControl());
        map.addControl(new MapTypeControl());
        map.setScrollWheelZoomEnabled(true);
        map.clearOverlays();

        map.addOverlay(new Marker(collegeCenter));
        Log.debug("Show CollegeBound");

        show(map);

    } catch (Exception e) {
        Log.error("EX " + e);
        loadError(e);
    }

}

From source file:com.apress.progwt.client.map.MyCollegeMap.java

License:Apache License

private Marker createMarker(final School school) {
    LatLng point = new LatLng(school.getLatitude(), school.getLongitude());
    if (point.getLatitude() == -1 && point.getLongitude() == -1) {
        return null;
    }//from   w w  w  . j  ava2s  . c o m

    final Marker marker = new Marker(point);
    marker.addMarkerClickListener(new MarkerClickListener() {
        public void onClick(Marker sender) {
            InfoWindow info = map.getInfoWindow();
            info.open(sender, new InfoWindowContent(new SchoolLink(school)));
        }

        public void onDoubleClick(Marker sender) {
        }
    });
    return marker;
}

From source file:com.google.gwt.gadgets.sample.traveler.client.TravelMap.java

License:Apache License

private Marker createMarker(final Location loc) {
    LatLng latlng = LatLng.newInstance(loc.getLatitude(), loc.getLongitude());
    final Marker marker = new Marker(latlng);
    marker.addMarkerClickHandler(new MarkerClickHandler() {
        public void onClick(MarkerClickEvent event) {
            final InfoWindow info = map.getInfoWindow();
            info.open(marker, newLocationDescription(loc, info, marker));
        }/*from  w ww. jav  a 2  s  .c o  m*/
    });
    return marker;
}

From source file:com.google.gwt.maps.sample.hellomaps.client.ClickDemo.java

License:Apache License

public ClickDemo() {
    map = new MapWidget(LatLng.newInstance(37.4419, -122.1419), 13);
    map.setSize("500px", "300px");
    initWidget(map);//  w  w  w . j  av  a 2s.  com

    map.addControl(new SmallMapControl());
    map.addControl(new MapTypeControl());

    map.addMapClickHandler(new MapClickHandler() {
        public void onClick(MapClickEvent e) {
            MapWidget sender = e.getSender();
            Overlay overlay = e.getOverlay();
            LatLng point = e.getLatLng();

            if (overlay != null && overlay instanceof Marker) {
                sender.removeOverlay(overlay);
            } else {
                sender.addOverlay(new Marker(point));
            }
        }
    });
}

From source file:com.google.gwt.maps.sample.hellomaps.client.Geocoder2Demo.java

License:Apache License

private void showAddress(final String address) {
    final InfoWindow info = map.getInfoWindow();
    geocoder.getLocations(address, new LocationCallback() {
        public void onFailure(int statusCode) {
            Window.alert("Sorry, we were unable to geocode that address");
        }/*from   w  w  w  .ja v  a  2s .  c  om*/

        public void onSuccess(JsArray<Placemark> locations) {
            Placemark place = locations.get(0);
            Marker marker = new Marker(place.getPoint());
            map.addOverlay(marker);
            String message = place.getAddress() + "<br>" + "<b>Country code:</b> " + place.getCountry();
            info.open(marker, new InfoWindowContent(message));
        }
    });
}

From source file:com.google.gwt.maps.sample.hellomaps.client.GeocoderDemo.java

License:Apache License

private void showAddress(final String address) {
    final InfoWindow info = map.getInfoWindow();
    geocoder.getLatLng(address, new LatLngCallback() {
        public void onFailure() {
            Window.alert(address + " not found");
        }/*from  w ww . ja v a 2 s.  c  o  m*/

        public void onSuccess(LatLng point) {
            map.setCenter(point, 13);
            Marker marker = new Marker(point);
            map.addOverlay(marker);
            info.open(marker, new InfoWindowContent(address));
            displayLatLng(point);
        }
    });
}

From source file:com.google.gwt.maps.sample.hellomaps.client.MarkerInfoWindowDemo.java

License:Apache License

private Marker createMarker(LatLng point, final int number) {
    final Marker marker = new Marker(point);

    marker.addMarkerClickHandler(new MarkerClickHandler() {
        public void onClick(MarkerClickEvent event) {
            InfoWindow info = map.getInfoWindow();
            info.open(marker, new InfoWindowContent("Marker #<b>" + number + "</b>"));
        }/*  ww w  .  j  a va 2  s .  com*/
    });

    return marker;
}

From source file:com.google.gwt.maps.sample.hellomaps.client.OverlayDemo.java

License:Apache License

private void displayOverlay() {

    map.clearOverlays();//from  ww  w .ja  v a  2 s  .  c o m

    LatLngBounds bounds = map.getBounds();
    LatLng southWest = bounds.getSouthWest();
    LatLng northEast = bounds.getNorthEast();
    double lngSpan = northEast.getLongitude() - southWest.getLongitude();
    double latSpan = northEast.getLatitude() - southWest.getLatitude();

    LatLng[] points = new LatLng[NUM_POINTS];

    for (int i = 0; i < NUM_POINTS; i++) {
        points[i] = LatLng.newInstance(southWest.getLatitude() + latSpan * Math.random(),
                southWest.getLongitude() + lngSpan * Math.random());
        GWT.log("points[" + i + "] = " + points[i] + " z-index = " + Marker.getZIndex(points[i].getLatitude()),
                null);
    }

    OverlayDemos selected = OverlayDemos.values()[actionListBox.getSelectedIndex()];

    switch (selected) {
    case TEST_TEN_MARKERS: {
        // Add markers in random locations on the map
        for (int i = 0; i < NUM_POINTS; i++) {
            map.addOverlay(new Marker(points[i]));
        }
    }
        break;

    case TEST_POLYLINE_ONE: {
        // Add a polyline with NUM_POINTS random points. Sort the points by
        // longitude so that the line does not intersect itself.
        Arrays.sort(points, new Comparator<LatLng>() {
            public int compare(LatLng p1, LatLng p2) {
                return new Double(p1.getLongitude()).compareTo(new Double(p2.getLongitude()));
            }
        });
        Polyline pline = new Polyline(points);
        map.addOverlay(pline);
        if (pline.getVertexCount() != NUM_POINTS) {
            Window.alert("Created polyline with " + NUM_POINTS + " vertices, but now it has "
                    + pline.getVertexCount());
        }
    }
        break;

    case TEST_POLYLINE_ENCODED: {
        // Add a polyline encoded in a string
        map.setCenter(LatLng.newInstance(40.71213418976525, -73.96785736083984), 15);
        Polyline pline = Polyline.fromEncoded("#3333cc", 10, 1.0, ENCODED_POINTS, 32, ENCODED_LEVELS, 4);
        map.addOverlay(pline);
    }
        break;
    case TEST_POLYLINE_GEODESIC: {
        LatLng nycToZurich[] = { LatLng.newInstance(40.75, -73.90), // New York
                LatLng.newInstance(47.3, 8.5) // Zurich
        };
        map.setCenter(LatLng.newInstance(40, -25), 2);
        Polyline pline = new Polyline(nycToZurich, "#FF0000", 1, .75, PolylineOptions.newInstance(false, true));
        map.addOverlay(pline);
    }
        break;
    case TEST_POLYLINE_ENCODED_TRANSPARENT: {
        // Add a polyline with transparency
        map.setCenter(LatLng.newInstance(40.71213418976525, -73.96785736083984), 15);
        Polyline pline = Polyline.fromEncoded(ENCODED_POINTS, 32, ENCODED_LEVELS, 4);
        map.addOverlay(pline);
    }
        break;

    case TEST_POLYGON_ENCODED: {
        // Add a polygon encoded as a series of polylines.
        map.setCenter(LatLng.newInstance(33.75951619957536, -84.39289301633835), 20);
        EncodedPolyline[] polylines = new EncodedPolyline[2];
        polylines[0] = EncodedPolyline.newInstance("au`mEz_bbO?sAbA@?pAcA?", 2, "BBBBB", 1, "#ff0000", 2, 0.9);

        polylines[1] = EncodedPolyline.newInstance("{t`mEt_bbO?eAx@??dAy@?", 2, "BBBBB", 1);
        polylines[1].setColor("#ff0000");
        polylines[1].setWeight(2);
        polylines[1].setOpacity(0.7);

        Polygon theFountain = Polygon.fromEncoded(polylines, true, "#ff0000", 0.2, true);
        map.addOverlay(theFountain);
        map.setCurrentMapType(MapType.getHybridMap());
    }
        break;

    default:
        Window.alert("Cannot handle selection: " + selected.valueOf());
        break;
    }
}

From source file:com.google.gwt.maps.sample.hellomaps.client.ReverseGeocoderDemo.java

License:Apache License

public ReverseGeocoderDemo() {
    VerticalPanel outer = new VerticalPanel();
    map = new MapWidget(LatLng.newInstance(0, 0), 1);
    outer.add(map);/*from  w  w  w .  j  a v a2  s.  co m*/
    map.setSize("500px", "300px");
    initWidget(outer);
    // Workaround for bug with click handler & setUItoDefaults() - see issue 260
    MapUIOptions opts = map.getDefaultUI();
    opts.setDoubleClick(false);
    map.setUI(opts);

    map.addMapClickHandler(new MapClickHandler() {

        public void onClick(final MapClickEvent event) {
            // Do not mis-interpret clicks on the info window and marker as
            // map click events to be reverse geocoded.
            if (event.getOverlay() != null) {
                return;
            }
            final Marker marker = new Marker(event.getLatLng());
            final VerticalPanel panel = new VerticalPanel();
            final InfoWindowContent content = new InfoWindowContent(panel);
            panel.add(new Label("LatLng: " + event.getLatLng().toString()));

            // Do a reverse geocode of this position
            geocoder.getLocations(event.getLatLng(), new LocationCallback() {

                public void onFailure(int statusCode) {
                    Window.alert("Failed to geocode position " + event.getLatLng() + ". Status: " + statusCode
                            + " " + StatusCodes.getName(statusCode));
                }

                public void onSuccess(JsArray<Placemark> locations) {
                    for (int i = 0; i < locations.length(); ++i) {
                        Placemark location = locations.get(i);
                        StringBuilder value = new StringBuilder();
                        if (location.getAddress() != null) {
                            value.append(location.getAddress());
                        } else {
                            if (location.getCity() != null) {
                                value.append(location.getCity());
                            }
                            if (location.getAdministrativeArea() != null) {
                                value.append(location.getAdministrativeArea() + ", ");
                            }
                            if (location.getCountry() != null) {
                                value.append(location.getCountry());
                            }
                        }
                        int ordinal = (i + 1);
                        panel.add(new Label("  " + ordinal + ") " + value.toString()));
                    }
                    map.addOverlay(marker);
                    map.getInfoWindow().open(marker, content);
                }
            });
            marker.addMarkerClickHandler(new MarkerClickHandler() {

                public void onClick(MarkerClickEvent markerClickEvent) {
                    if (!map.getInfoWindow().isVisible()) {
                        map.getInfoWindow().open(marker, content);
                    }
                }
            });
        }

    });
    geocoder = new Geocoder();
}

From source file:com.google.gwt.sample.vanfood.client.VanFood.java

private Marker createMarker(Vendor v) {
    double lat = v.getLat();
    double lon = v.getLon();
    final String name = v.getName();
    final String address = v.getAddress();
    LatLng point = LatLng.newInstance(lat, lon);
    final Marker marker = new Marker(point);

    marker.addMarkerClickHandler(new MarkerClickHandler() {
        public void onClick(MarkerClickEvent event) {
            InfoWindow info = map.getInfoWindow();
            info.open(marker, new InfoWindowContent("<b>" + name + "<br>" + address + "</b>"));
        }//from  w w w .  j av a 2 s.co  m
    });
    System.out.println(v.toString());
    return marker;
}