Example usage for android.location Address setLatitude

List of usage examples for android.location Address setLatitude

Introduction

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

Prototype

public void setLatitude(double latitude) 

Source Link

Document

Sets the latitude associated with this address.

Usage

From source file:org.microg.networklocation.backends.mapquest.NominatimGeocodeSource.java

private Address parseResponse(Locale locale, JSONObject result) throws JSONException {
    if (!result.has(WIRE_LATITUDE) || !result.has(WIRE_LONGITUDE) || !result.has(WIRE_ADDRESS)) {
        return null;
    }/* ww w.java2s.  c o m*/
    Address address = new Address(locale);
    address.setLatitude(result.getDouble(WIRE_LATITUDE));
    address.setLatitude(result.getDouble(WIRE_LONGITUDE));

    int line = 0;
    JSONObject a = result.getJSONObject(WIRE_ADDRESS);

    if (a.has(WIRE_THOROUGHFARE)) {
        address.setAddressLine(line++, a.getString(WIRE_THOROUGHFARE));
        address.setThoroughfare(a.getString(WIRE_THOROUGHFARE));
    }
    if (a.has(WIRE_SUBLOCALITY)) {
        address.setSubLocality(a.getString(WIRE_SUBLOCALITY));
    }
    if (a.has(WIRE_POSTALCODE)) {
        address.setAddressLine(line++, a.getString(WIRE_POSTALCODE));
        address.setPostalCode(a.getString(WIRE_POSTALCODE));
    }
    if (a.has(WIRE_LOCALITY_CITY)) {
        address.setAddressLine(line++, a.getString(WIRE_LOCALITY_CITY));
        address.setLocality(a.getString(WIRE_LOCALITY_CITY));
    } else if (a.has(WIRE_LOCALITY_TOWN)) {
        address.setAddressLine(line++, a.getString(WIRE_LOCALITY_TOWN));
        address.setLocality(a.getString(WIRE_LOCALITY_TOWN));
    } else if (a.has(WIRE_LOCALITY_VILLAGE)) {
        address.setAddressLine(line++, a.getString(WIRE_LOCALITY_VILLAGE));
        address.setLocality(a.getString(WIRE_LOCALITY_VILLAGE));
    }
    if (a.has(WIRE_SUBADMINAREA)) {
        address.setAddressLine(line++, a.getString(WIRE_SUBADMINAREA));
        address.setSubAdminArea(a.getString(WIRE_SUBADMINAREA));
    }
    if (a.has(WIRE_ADMINAREA)) {
        address.setAddressLine(line++, a.getString(WIRE_ADMINAREA));
        address.setAdminArea(a.getString(WIRE_ADMINAREA));
    }
    if (a.has(WIRE_COUNTRYNAME)) {
        address.setAddressLine(line++, a.getString(WIRE_COUNTRYNAME));
        address.setCountryName(a.getString(WIRE_COUNTRYNAME));
    }
    if (a.has(WIRE_COUNTRYCODE)) {
        address.setCountryCode(a.getString(WIRE_COUNTRYCODE));
    }

    return address;
}

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 w w . j a  v  a2  s. c om*/
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.iescities.pilot.rovereto.roveretoexplorer.fragments.event.EventDetailsFragment.java

/**
 * /*from   ww  w .  j  a v a 2s . c  o  m*/
 */
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:eu.trentorise.smartcampus.trentinofamiglia.fragments.track.TrackDetailsFragment.java

@Override
public void onStart() {
    super.onStart();
    if (getTrack() != null) {
        ImageView certifiedIcon = (ImageView) this.getView().findViewById(R.id.track_details_icon);
        Drawable icon = null;//  ww w. j ava2s.c  om
        certifiedIcon
                .setImageDrawable(getResources().getDrawable(CategoryHelper.getIconByType(mTrack.getType())));

        // title
        TextView tv = (TextView) this.getView().findViewById(R.id.track_details_title);
        tv.setText(mTrack.getTitle());

        /*
         * BUTTONS
         */

        // map
        ImageButton mapBtn = (ImageButton) getView().findViewById(R.id.trackdetails_map);
        mapBtn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                ArrayList<BaseDTObject> list = new ArrayList<BaseDTObject>();
                list.add(mTrack);
                MapManager.switchToMapView(list, mFragment);
            }
        });

        // directions
        ImageButton directionsBtn = (ImageButton) getView().findViewById(R.id.trackdetails_directions);
        directionsBtn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Address to = Utils.getTrackAsGoogleAddress(mTrack);
                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);
            }
        });
        /*
         * END BUTTONS
         */

        // description, optional
        tv = (TextView) this.getView().findViewById(R.id.track_details_descr);
        String customDescr = mTrack.customDescription(getActivity());
        if (customDescr != null && customDescr.length() > 0) {
            tv.setText(Html.fromHtml(customDescr));
        } else {
            ((LinearLayout) this.getView().findViewById(R.id.trackdetails)).removeView(tv);
        }

        commentsHandler = new CommentsHandler(getTrack(), getActivity(), getView());
    }
}

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;// ww w  .  j  a va2 s  .c om

    /*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:edu.usf.cutr.opentripplanner.android.tasks.OTPGeocoding.java

protected Long doInBackground(String... reqs) {
    long count = reqs.length;

    String address = reqs[0];// w ww . j  a va 2s.  c  om
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

    if (address == null || address.equalsIgnoreCase("")) {
        return count;
    }

    if (address.equalsIgnoreCase(context.getString(R.string.my_location))) {
        String currentLat = reqs[1];
        String currentLng = reqs[2];
        LatLng latLng = new LatLng(Double.parseDouble(currentLat), Double.parseDouble(currentLng));

        Address addressReturn = new Address(context.getResources().getConfiguration().locale);
        addressReturn.setLatitude(latLng.latitude);
        addressReturn.setLongitude(latLng.longitude);
        addressReturn.setAddressLine(addressReturn.getMaxAddressLineIndex() + 1,
                context.getString(R.string.my_location));

        addressesReturn.add(addressReturn);

        return count;
    }

    ArrayList<Address> addresses = null;

    if (prefs.getBoolean(OTPApp.PREFERENCE_KEY_USE_ANDROID_GEOCODER, true)) {
        Log.d("test", "create a geocoder");
        Geocoder gc = new Geocoder(context);
        try {
            if (selectedServer != null) {
                addresses = (ArrayList<Address>) gc.getFromLocationName(address,
                        context.getResources().getInteger(R.integer.geocoder_max_results),
                        selectedServer.getLowerLeftLatitude(), selectedServer.getLowerLeftLongitude(),
                        selectedServer.getUpperRightLatitude(), selectedServer.getUpperRightLongitude());
            } else {
                addresses = (ArrayList<Address>) gc.getFromLocationName(address,
                        context.getResources().getInteger(R.integer.geocoder_max_results));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    addresses = filterAddressesBBox(addresses);

    if ((addresses == null) || addresses.isEmpty()) {
        addresses = searchPlaces(address);

        for (int i = 0; i < addresses.size(); i++) {
            Address addr = addresses.get(i);
            String str = addr.getAddressLine(0);
            List<String> addrLines = Arrays.asList(str.split(", "));
            for (int j = 0; j < addrLines.size(); j++) {
                addr.setAddressLine(j, addrLines.get(j));
            }
        }
    }

    addresses = filterAddressesBBox(addresses);

    addressesReturn.addAll(addresses);

    return count;
}

From source file:eu.trentorise.smartcampus.trentinofamiglia.fragments.poi.PoiDetailsFragment.java

@Override
public void onStart() {
    super.onStart();
    if (getPOI() != null) {
        ImageView certifiedIcon = (ImageView) this.getView().findViewById(R.id.poi_details_icon);
        ImageView bannerCertifiedIcon = (ImageView) this.getView().findViewById(R.id.banner_certified);

        Drawable icon = null;//from  w w  w .j  a  v  a2  s  .com
        if (CategoryHelper.CAT_POI_FAMILY_IN_TRENTINO.equals(mPoi.getType())) {
            icon = POIHelper.getDrawablePoiFamilyTrentinoDetail(getActivity(), mPoi);
            bannerCertifiedIcon.setVisibility(View.VISIBLE);
        } else if (CategoryHelper.CAT_POI_FAMILY_AUDIT.equals(mPoi.getType())) {
            icon = POIHelper.getDrawablePoiFamilyAuditDetail(getActivity(), mPoi);
            bannerCertifiedIcon.setVisibility(View.VISIBLE);

        }
        certifiedIcon.setImageDrawable(icon);

        // title
        TextView tv = (TextView) this.getView().findViewById(R.id.poi_details_title);
        tv.setText(mPoi.getTitle());

        /*
         * BUTTONS
         */

        // map
        ImageButton mapBtn = (ImageButton) getView().findViewById(R.id.poidetails_map);

        mapBtn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                ArrayList<BaseDTObject> list = new ArrayList<BaseDTObject>();
                list.add(mPoi);
                MapManager.switchToMapView(list, mFragment);
            }
        });

        // directions
        ImageButton directionsBtn = (ImageButton) getView().findViewById(R.id.poidetails_directions);
        directionsBtn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Address to = Utils.getPOIasGoogleAddress(mPoi);
                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);
            }
        });

        if (mPoi.getLocation()[0] == 0 && mPoi.getLocation()[1] == 0) {
            mapBtn.setVisibility(View.INVISIBLE);
            directionsBtn.setVisibility(View.GONE);
        }

        /*
         * END BUTTONS
         */

        // description, optional
        tv = (TextView) this.getView().findViewById(R.id.poi_details_descr);
        String customDesc = POIHelper.customDescription(mPoi, getActivity());
        if (customDesc != null && customDesc.length() > 0) {
            tv.setText(Html.fromHtml(customDesc));
        } else {
            ((LinearLayout) this.getView().findViewById(R.id.poidetails)).removeView(tv);
        }

        //         // notes
        //         tv = (TextView) this.getView().findViewById(R.id.poi_details_notes);
        //         ((LinearLayout) this.getView().findViewById(R.id.poidetails)).removeView(tv);

        // location
        tv = (TextView) this.getView().findViewById(R.id.poi_details_loc);
        tv.setText(Html.fromHtml("<a href=\"\">" + Utils.getPOIshortAddress(mPoi) + "</a> "));
        tv.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                ArrayList<BaseDTObject> list = new ArrayList<BaseDTObject>();
                list.add(mPoi);
                MapManager.switchToMapView(list, PoiDetailsFragment.this);
            }
        });

        commentsHandler = new CommentsHandler(getPOI(), getActivity(), getView());

    }
}

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 {/*  w  w w.j  a va 2  s . c o  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  www.j  a v a 2s  .c  o m*/

        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();
    }
}

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

private Address getLocationsFromParam(String param, Address from, Map<String, List<String>> locations,
        String fromString) {//  w w  w .  j  a v a2  s.co  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;
}