kabit999 / gwt-google-apis

Automatically exported from code.google.com/p/gwt-google-apis
0 stars 0 forks source link

FR: Update LocationCallback #21

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I'd really like to see the methods in
com.google.gwt.maps.client.geocode.LocationCallback have the original
address in their parameters.  Looking at Geocoder.getLocations, this
shouldn't be too hard to do.  I was thinking of something like this:

From com.google.gwt.maps.client.geocode.Geocoder:

  public void getLocations(String address, final LocationCallback callback) {
    GeocoderImpl.impl.getLocations(jsoPeer, address, new LocationsCallback() {
      public void callback(Response response) {
        int statusCode = response.getStatus().getCode();
        if (statusCode == StatusCodes.SUCCESS) {
          JSList placemarkList = response.getPlacemarks();
          Placemark[] placemarks = new Placemark[placemarkList.size()];
          JsUtil.toArray(placemarkList, placemarks);
          callback.onSuccess(placemarks, address);
        } else {
          callback.onFailure(statusCode, address);
        }
      }
    });
  }

Original issue reported on code.google.com by ebesse...@gmail.com on 19 Sep 2007 at 1:38

GoogleCodeExporter commented 9 years ago
One way to handle this is to declare field marked 'final' to make a copy of the
address string, then you can reference it from inside your LocationCallback
implementation.  In the example below, I did this twice, to reference an 
InfoWindow
object as well:

  private void displayWithGeocoder(InfoWindow w, String address) {

    final String addressCopy = address;
    final InfoWindow wCopy = w;

    Geocoder g = new Geocoder();
    g.getLocations(address, new LocationCallback() {
      public void onFailure(int statusCode) {
        GWT.log("Error: "+statusCode+" Failed to retrieve address: "+addressCopy, 
            null);
      }
      public void onSuccess(Placemark[] locations) {
        GWT.log("Got "+locations.length+" locations returned. Address is " +
addressCopy, 
            null);
        if (locations.length > 0) {
          wCopy.open(locations[0].getPoint(), 
              new InfoWindowContent("Found :" + locations[0].getAddress()));
        }
      }
    });

  }

Original comment by gwt.team...@gmail.com on 14 Jan 2008 at 3:58

GoogleCodeExporter commented 9 years ago
Now I am thinking we should change this callback model to use the handler/event
pattern that we're putting in to support GEvent.

Original comment by galgwt.reviews@gmail.com on 5 Apr 2008 at 3:53

GoogleCodeExporter commented 9 years ago
If we do this, we will need to look at the following types which use a callback 
pattern:

DirectionsCallback, LatLngCallback, LocationCallback, GeoXMLLoadCallback

Original comment by stxmen...@gmail.com on 23 Jul 2008 at 2:40

GoogleCodeExporter commented 9 years ago
The Maps v2 API is now deprecated.

Original comment by zundel@google.com on 28 May 2010 at 6:15