Example usage for android.location Address Address

List of usage examples for android.location Address Address

Introduction

In this page you can find the example usage for android.location Address Address.

Prototype

public Address(Locale locale) 

Source Link

Document

Constructs a new Address object set to the given Locale and with all other fields initialized to null or false.

Usage

From source file:info.wncwaterfalls.app.ResultsActivity.java

@Override
public void onLocationChanged(Location currentLocation) {
    mOriginLocation = currentLocation; // Yay!
    // If the reported accuracy is within 1km, we're good.
    if (mOriginLocation != null) {
        float accuracy = currentLocation.getAccuracy();
        if (accuracy <= 1000.0) {
            // Good enough.
            mOriginAddress = new Address(new Locale("en", "US"));
            mOriginAddress.setFeatureName("Current Location");
            mOriginAddress.setLatitude(mOriginLocation.getLatitude());
            mOriginAddress.setLongitude(mOriginLocation.getLongitude());
            mFoundOrigin = true;/*  w ww . j av  a 2s.  com*/
            if (mLocationRequestor != null) {
                // Notify the fragment, which should be sitting there waiting for us,
                // that we're *finally* done getting the location, which will then
                // make IT initialize its loader, and call our onWaterfallQuery method.
                ((ResultsMapFragment) mLocationRequestor).onLocationDetermined();
            } else {
                //Log.d(TAG, "Ooops, lol, requesting fragment is null.");
            }
            // Turn off updates.
            mLocationClient.removeLocationUpdates(this);
        } else { // Otherwise, we wait for more updates, up to 4.
            if (mNumUpdates >= 5) {
                // 5 inaccurate locations. Give up.
                mLocationClient.removeLocationUpdates(this);
                mOriginAddress = new Address(new Locale("en", "US"));
                ((ResultsMapFragment) mLocationRequestor).onLocationDetermined();
            }
            mNumUpdates += 1;
        }
    } else {
        // Lame.
        mOriginAddress = new Address(new Locale("en", "US"));
    }
}

From source file:it.smartcampuslab.riciclo.geo.OSMAddress.java

/**
 * Convert the object to {@link Address} data structure
 * @return converted {@link Address} instance with
 * address line corresponding to the formatted address of the object
 * with lat/lon, country name, and locality filled. 
 *//*from  w ww.  j  av  a  2 s  .c  o  m*/
public Address toAddress() {
    Address a = new Address(locale);
    a.setAddressLine(0, formattedAddress());
    a.setCountryName(country());
    a.setLatitude(location[0]);
    a.setLongitude(location[1]);
    a.setLocality(city());
    return a;
}

From source file:eu.trentorise.smartcampus.jp.PlanNewJourneyFragment.java

private Address getLocationsFromParam(String param, Address from, Map<String, List<String>> locations,
        String fromString) {/*from   w ww .j  a  v  a2s. c o  m*/
    if (locations.containsKey(param)) {
        fromString = locations.get(param).get(0);
    }

    if (fromString != null) {
        from = new Address(Locale.getDefault());
        List<String> fromList = Arrays.asList(fromString.split(","));
        Log.e(getClass().getSimpleName(), fromString);
        from.setLatitude(Double.parseDouble(fromList.get(0)));
        from.setLongitude(Double.parseDouble(fromList.get(1)));
    }
    return from;
}

From source file:com.ternup.caddisfly.activity.SurveyActivity.java

private long saveData() {

    if (isFormIncomplete()) {
        return -1;
    }/*w  w w. j av  a2s .  co m*/

    MainApp mainApp = (MainApp) getApplicationContext();
    ContentValues values = new ContentValues();
    values.put(LocationTable.COLUMN_DATE, (new Date().getTime()));

    String featureName = mainApp.address.getFeatureName();
    if (featureName == null || featureName.isEmpty()) {
        return -1;
    }
    values.put(LocationTable.COLUMN_NAME, featureName);

    values.put(LocationTable.COLUMN_STREET,
            mainApp.address.getThoroughfare() == null ? "" : mainApp.address.getThoroughfare());
    values.put(LocationTable.COLUMN_TOWN,
            mainApp.address.getSubLocality() == null ? "" : mainApp.address.getSubLocality());
    values.put(LocationTable.COLUMN_CITY,
            mainApp.address.getLocality() == null ? "" : mainApp.address.getLocality());
    values.put(LocationTable.COLUMN_STATE,
            mainApp.address.getAdminArea() == null ? "" : mainApp.address.getAdminArea());
    values.put(LocationTable.COLUMN_COUNTRY,
            mainApp.address.getCountryName() == null ? "" : mainApp.address.getCountryName());

    values.put(LocationTable.COLUMN_LONGITUDE, mainApp.location.getLongitude());
    values.put(LocationTable.COLUMN_LATITUDE, mainApp.location.getLatitude());
    values.put(LocationTable.COLUMN_ACCURACY, mainApp.location.getAccuracy());

    Bundle bundle = mainApp.address.getExtras();
    int sourceType = bundle.getInt("sourceType", 0);
    String notes = "";
    if (mNotesFragment != null) {
        notes = mNotesFragment.getNotes();
    }
    values.put(LocationTable.COLUMN_SOURCE, sourceType);
    values.put(LocationTable.COLUMN_NOTES, notes);

    Uri uri = getContentResolver().insert(LocationContentProvider.CONTENT_URI, values);
    long id = ContentUris.parseId(uri);

    PreferencesUtils.setLong(this, R.string.currentLocationId, id);

    mainApp.address = new Address(Locale.getDefault());
    mainApp.location = new Location(LocationManager.GPS_PROVIDER);

    File file = new File(FileUtils.getStoragePath(this, 0, "", true) + "photo");

    FileUtils.deleteFolder(this, id, "");

    file.renameTo(new File(FileUtils.getStoragePath(this, id, "", true) + "photo"));

    return id;

}

From source file:edu.usf.cutr.opentripplanner.android.tasks.OTPGeocoding.java

private ArrayList<Address> searchPlaces(String name) {
    HashMap<String, String> params = new HashMap<String, String>();
    Places p;/*from www .  ja  va2  s. c o m*/

    /*params.put(Itract.PARAM_NAME, name);
    if (selectedServer != null) {
       params.put(Itract.PARAM_LAT, Double.toString(selectedServer.getGeometricalCenterLatitude()));
       params.put(Itract.PARAM_LON, Double.toString(selectedServer.getGeometricalCenterLongitude()));
    }
    p = new Itract();*/

    if (placesService.equals(context.getResources().getString(R.string.geocoder_google_places))) {
        params.put(GooglePlaces.PARAM_NAME, name);
        if (selectedServer != null) {
            params.put(GooglePlaces.PARAM_LOCATION,
                    Double.toString(selectedServer.getGeometricalCenterLatitude()) + ","
                            + Double.toString(selectedServer.getGeometricalCenterLongitude()));
            params.put(GooglePlaces.PARAM_RADIUS, Double.toString(selectedServer.getRadius()));
        }
        p = new GooglePlaces(getKeyFromResource());

        Log.v(TAG, "Using Google Places!");
    } else {
        params.put(Nominatim.PARAM_NAME, name);
        if (selectedServer != null) {
            params.put(Nominatim.PARAM_LEFT, Double.toString(selectedServer.getLowerLeftLongitude()));
            params.put(Nominatim.PARAM_TOP, Double.toString(selectedServer.getLowerLeftLatitude()));
            params.put(Nominatim.PARAM_RIGHT, Double.toString(selectedServer.getUpperRightLongitude()));
            params.put(Nominatim.PARAM_BOTTOM, Double.toString(selectedServer.getUpperRightLatitude()));
        }

        p = new Nominatim();

        Log.v(TAG, "Using Nominatim!");
    }

    ArrayList<POI> pois = new ArrayList<POI>();
    pois.addAll(p.getPlaces(params));

    ArrayList<Address> addresses = new ArrayList<Address>();

    for (int i = 0; i < pois.size(); i++) {
        POI poi = pois.get(i);
        Log.v(TAG, poi.getName() + " " + poi.getLatitude() + "," + poi.getLongitude());
        Address addr = new Address(context.getResources().getConfiguration().locale);
        addr.setLatitude(poi.getLatitude());
        addr.setLongitude(poi.getLongitude());
        String addressLine;

        if (poi.getAddress() != null) {
            if (!poi.getAddress().contains(poi.getName())) {
                addressLine = (poi.getName() + ", " + poi.getAddress());
            } else {
                addressLine = poi.getAddress();
            }
        } else {
            addressLine = poi.getName();
        }
        addr.setAddressLine(addr.getMaxAddressLineIndex() + 1, addressLine);
        addresses.add(addr);
    }

    return addresses;
}

From source file:eu.iescities.pilot.rovereto.roveretoexplorer.fragments.event.EventDetailsFragment.java

/**
 * /*from w  w  w. j  a  v  a  2s. c om*/
 */
protected void callBringMeThere() {
    Address to = new Address(Locale.getDefault());
    to.setLatitude(mEvent.getLocation()[0]);
    to.setLongitude(mEvent.getLocation()[1]);
    Address from = null;
    GeoPoint mylocation = MapManager.requestMyLocation(getActivity());
    if (mylocation != null) {
        from = new Address(Locale.getDefault());
        from.setLatitude(mylocation.getLatitudeE6() / 1E6);
        from.setLongitude(mylocation.getLongitudeE6() / 1E6);
    }
    DTHelper.bringmethere(getActivity(), from, to);

}

From source file:com.example.loc.MainActivity.java

public static List<Address> getFromLocation(double lat, double lng, int maxResult) {

    String address = String.format(Locale.ENGLISH,
            "http://maps.googleapis.com/maps/api/geocode/json?latlng=%1$f,%2$f&sensor=true&language="
                    + Locale.getDefault().getCountry(),
            lat, lng);/*from   w w w  .  j a v  a 2  s.  c om*/
    HttpGet httpGet = new HttpGet(address);
    HttpClient client = new DefaultHttpClient();
    HttpResponse response;
    StringBuilder stringBuilder = new StringBuilder();

    List<Address> retList = null;

    try {
        response = client.execute(httpGet);
        HttpEntity entity = response.getEntity();
        InputStream stream = entity.getContent();
        int b;
        while ((b = stream.read()) != -1) {
            stringBuilder.append((char) b);
        }

        JSONObject jsonObject = new JSONObject();
        jsonObject = new JSONObject(stringBuilder.toString());

        retList = new ArrayList<Address>();

        if ("OK".equalsIgnoreCase(jsonObject.getString("status"))) {
            JSONArray results = jsonObject.getJSONArray("results");
            for (int i = 0; i < results.length(); i++) {
                JSONObject result = results.getJSONObject(i);
                String indiStr = result.getString("formatted_address");
                Address addr = new Address(Locale.ENGLISH);
                addr.setAddressLine(0, indiStr);
                retList.add(addr);
            }
        }

    } catch (ClientProtocolException e) {
        Log.e(LocationUtils.APPTAG, "Error calling Google geocode webservice.", e);
    } catch (IOException e) {
        Log.e(LocationUtils.APPTAG, "Error calling Google geocode webservice.", e);
    } catch (JSONException e) {
        Log.e(LocationUtils.APPTAG, "Error parsing Google geocode webservice response.", e);
    }

    return retList;
}

From source file:eu.trentorise.smartcampus.jp.PlanNewJourneyFragment.java

private void findAddressForField(final String field, Location location) {
    List<Address> hereAddressesList = new SCGeocoder(getSherlockActivity()).findAddressesAsync(location);
    if (hereAddressesList != null && !hereAddressesList.isEmpty()) {
        Address hereAddress = hereAddressesList.get(0);
        savePosition(hereAddress, field);
    } else {/*from w  w  w  .  jav  a 2s . co m*/
        Address customAddress = new Address(Locale.getDefault());
        customAddress.setLatitude(location.getLatitude());
        customAddress.setLongitude(location.getLongitude());
        customAddress.setAddressLine(0, "LON " + Double.toString(customAddress.getLongitude()) + ", LAT "
                + Double.toString(customAddress.getLatitude()));
        savePosition(customAddress, field);
    }
}

From source file:eu.trentorise.smartcampus.jp.PlanNewJourneyFragment.java

protected void createFavoritesDialog(final String field) {
    if (userPrefsHolder != null && userPrefsHolder.getFavorites() != null
            && !userPrefsHolder.getFavorites().isEmpty()) {
        final List<Position> list = userPrefsHolder.getFavorites();
        String[] items = new String[list.size()];
        for (int i = 0; i < items.length; i++) {
            items[i] = list.get(i).getName();
        }/*from  w  ww.  j  a v  a2 s.  c  om*/

        AlertDialog.Builder builder = new AlertDialog.Builder(getSherlockActivity());
        builder.setTitle(getString(R.string.favorites_title));

        builder.setItems(items, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                // to be replaced with real favorites list
                Address address = new Address(Locale.getDefault());
                Position p = list.get(which);
                address.setLatitude(Double.parseDouble(p.getLat()));
                address.setLongitude(Double.parseDouble(p.getLon()));
                address.setAddressLine(0, p.getName());
                savePosition(address, field);

                if (FROM.equalsIgnoreCase(field)) {
                    ImageButton ibtn = (ImageButton) getView().findViewById(R.id.plannew_from_star);
                    ibtn.setImageResource(R.drawable.ic_fav_star_active);
                    ibtn.setTag(true);
                } else if (TO.equalsIgnoreCase(field)) {
                    ImageButton ibtn = (ImageButton) getView().findViewById(R.id.plannew_to_star);
                    ibtn.setImageResource(R.drawable.ic_fav_star_active);
                    ibtn.setTag(true);
                }
            }
        });

        builder.create().show();
    } else {
        Toast.makeText(getActivity(), R.string.favorites_empty_list, Toast.LENGTH_SHORT).show();
    }
}