public GoogleCoordinates(final GeocoderResult result) throws GeocoderException { super(); if (result == null) { throw new GeocoderException("No valid geocoder result found!"); } final GeocoderGeometry geometry = result.getGeometry(); if (geometry == null) { throw new GeocoderException("No geometry found in Google geocoding response!"); } final LatLng latLng = geometry.getLocation(); if (latLng == null) { throw new GeocoderException("No latitude/longitude found in Google geocoding response!"); } setCoordinates(latLng.getLng().doubleValue(), latLng.getLat().doubleValue()); } }
public static double[] getLatLngForAddr(String addr) { if (addr == null) return null; Geocoder geocoder = new Geocoder(); GeocoderRequest geocoderRequest; GeocodeResponse geocoderResponse; geocoderRequest = new GeocoderRequestBuilder() .setAddress(addr) .setLanguage("en").getGeocoderRequest(); geocoderResponse = geocoder.geocode(geocoderRequest); if (geocoderResponse != null) { if (geocoderResponse.getStatus() == GeocoderStatus.OK) { if (!geocoderResponse.getResults().isEmpty()) { GeocoderResult geocoderResult = // Get the first result geocoderResponse.getResults().iterator().next(); double[] loc = new double[2]; LatLng ll = geocoderResult.getGeometry().getLocation(); loc[0] = ll.getLat().doubleValue(); loc[1] = ll.getLng().doubleValue(); return loc; } } } return null; }
double longitudeArrivee; if (resultDepart != null) { latitudeDepart = resultDepart.getGeometry().getLocation().getLat().doubleValue(); longitudeDepart = resultDepart.getGeometry().getLocation().getLng().doubleValue(); } else { latitudeArrivee = resultArrivee.getGeometry().getLocation().getLat().doubleValue(); longitudeArrivee = resultArrivee.getGeometry().getLocation().getLng().doubleValue(); } else {
double longitudeArrivee; if (resultDepart != null) { latitudeDepart = resultDepart.getGeometry().getLocation().getLat().doubleValue(); longitudeDepart = resultDepart.getGeometry().getLocation().getLng().doubleValue(); } else { latitudeArrivee = resultArrivee.getGeometry().getLocation().getLat().doubleValue(); longitudeArrivee = resultArrivee.getGeometry().getLocation().getLng().doubleValue(); } else {