Example usage for com.google.gwt.maps.client.placeslib PlacesService newInstance

List of usage examples for com.google.gwt.maps.client.placeslib PlacesService newInstance

Introduction

In this page you can find the example usage for com.google.gwt.maps.client.placeslib PlacesService newInstance.

Prototype

public static final PlacesService newInstance(Element htmlDivElement) 

Source Link

Document

Creates a new instance of the PlacesService that renders attributions in the specified container.

Usage

From source file:com.google.gwt.maps.testing.client.maps.PlaceSearchMapWidget.java

License:Apache License

private void searchRequest(LatLng clickLocation) {
    String[] types = new String[1];
    types[0] = "establishment";

    PlaceSearchRequest request = PlaceSearchRequest.newInstance();
    request.setLocation(clickLocation);/*from ww  w . j a  v  a 2  s.c o m*/
    request.setRadius(500d);
    // TODO add more AutocompleteTypes...
    // request.setTypes(AutocompleteType.ESTABLISHMENT);
    request.setTypes(types);

    PlacesService placeService = PlacesService.newInstance(mapWidget);
    placeService.nearbySearch(request, new PlaceSearchHandler() {

        @Override
        public void onCallback(JsArray<PlaceResult> results, PlaceSearchPagination pagination,
                PlacesServiceStatus status) {

            if (status == PlacesServiceStatus.OK) {
                Window.alert("I found this many places " + results.length());

                // look up the details for the first place
                if (results.length() > 0) {
                    PlaceResult result = results.get(0);
                    String reference = result.getReference();
                    getPlaceDetails(reference);

                    String json = new JSONObject(result).toString();
                    GWT.log("details=" + json);
                }
            } else {
                Window.alert("Status is: status=" + status);
            }
        }

    });
}

From source file:com.google.gwt.maps.testing.client.maps.PlaceSearchMapWidget.java

License:Apache License

private void getPlaceDetails(String reference) {
    if (reference == null || reference.isEmpty()) {
        return;/*from  ww  w .  j a v  a  2 s  .c o  m*/
    }

    PlacesService placeService = PlacesService.newInstance(mapWidget);
    PlaceDetailsRequest request = PlaceDetailsRequest.newInstance();
    request.setReference(reference);

    placeService.getDetails(request, new PlaceDetailsHandler() {
        @Override
        public void onCallback(PlaceResult result, PlacesServiceStatus status) {
            if (status == PlacesServiceStatus.OK) {
                Window.alert("Found place details: name=" + result.getName());
            } else {
                String json = new JSONObject(result).toString();
                System.out.println("details=" + json);
                Window.alert("Status is: status=" + status + " ::: " + json);
            }
        }
    });
}