Example usage for android.location Address getFeatureName

List of usage examples for android.location Address getFeatureName

Introduction

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

Prototype

public String getFeatureName() 

Source Link

Document

Returns the feature name of the address, for example, "Golden Gate Bridge", or null if it is unknown

Usage

From source file:grandroid.geo.Geocoder.java

public static String convertAddress(double lat, double lng) throws Exception {
    List<Address> adds = getFromLocation(lat, lng, 1);
    if (adds == null || adds.isEmpty()) {
        throw new Exception("no address can be found");
    } else {/*from w ww. ja  v  a 2  s .co  m*/
        Address add = adds.get(0);
        if (add.getFeatureName() == null) {
            return add.getAdminArea() + add.getLocality() + add.getAddressLine(0);
        } else {
            return add.getFeatureName();
        }
    }
}

From source file:com.googlecode.android_scripting.jsonrpc.JsonBuilder.java

private static JSONObject buildJsonAddress(Address address) throws JSONException {
    JSONObject result = new JSONObject();
    result.put("admin_area", address.getAdminArea());
    result.put("country_code", address.getCountryCode());
    result.put("country_name", address.getCountryName());
    result.put("feature_name", address.getFeatureName());
    result.put("phone", address.getPhone());
    result.put("locality", address.getLocality());
    result.put("postal_code", address.getPostalCode());
    result.put("sub_admin_area", address.getSubAdminArea());
    result.put("thoroughfare", address.getThoroughfare());
    result.put("url", address.getUrl());
    return result;
}

From source file:com.mycompany.hw4.Maps.java

private void setUpMap() {
    Intent intent = getIntent();//from  w w w.j  av  a  2 s. c  o  m
    ArrayList<Parcelable> addresses = (ArrayList<Parcelable>) intent.getExtras()
            .getParcelableArrayList(MainActivity.LOCATION_MESSAGE);
    LatLng location = new LatLng(0, 0);
    PolylineOptions polyOpt = new PolylineOptions().geodesic(true).color(0xDDEE3333);

    for (Parcelable parcel : addresses) {
        Address address = (Address) parcel;
        location = new LatLng(address.getLatitude(), address.getLongitude());
        polyOpt.add(location);

        String marker;
        if (address.getFeatureName() != null) {
            marker = address.getFeatureName();
        } else if (address.getAddressLine(0) != null) {
            marker = address.getAddressLine(0);
        } else {
            marker = "Marker";
        }

        String snip = address.getLatitude() + " " + address.getLongitude() + "";

        map.addMarker(new MarkerOptions().position(location).title(marker).snippet(snip));
    }

    map.animateCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition(location, 14, 45, 0)));
    map.addPolyline(polyOpt);

    map.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
        @Override
        public boolean onMarkerClick(Marker marker) {
            map.animateCamera(
                    CameraUpdateFactory.newCameraPosition(new CameraPosition(marker.getPosition(), 14, 45, 0)));
            marker.showInfoWindow();
            return true;
        }
    });
}

From source file:com.mhennessy.mapfly.MainActivity.java

public void setMapLocation(String locationName) {
    try {/*from   w ww  .  j a v  a 2s.c om*/
        List<Address> possibleLocations = mGeocoder.getFromLocationName(locationName, 1);
        if (possibleLocations != null && !possibleLocations.isEmpty()) {
            Address address = possibleLocations.get(0);
            setTitle(address.getFeatureName());
            CameraPosition position = new CameraPosition.Builder()
                    .target(new LatLng(address.getLatitude(), address.getLongitude())).zoom(DEFAULT_ZOOM)
                    .tilt(DEFAULT_TILT).build();
            animateCameraToPosition(position, null);
        }
    } catch (IOException e) {
        Log.e(TAG, "Error getting address from location name.");
    }
}

From source file:org.microg.gms.ui.PlacePickerActivity.java

@Override
public void onMapEvent(Event event, MapPosition position) {
    place.viewport = GmsMapsTypeHelper.toLatLngBounds(mapView.map().viewport().getBBox(null, 0));
    resultIntent.putExtra(LocationConstants.EXTRA_FINAL_BOUNDS, place.viewport);
    place.latLng = GmsMapsTypeHelper.toLatLng(position.getGeoPoint());
    place.name = "";
    place.address = "";
    updateInfoText();// w  w w.j  av  a  2 s .  co  m
    if (geocoderInProgress.compareAndSet(false, true)) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    LatLng ll = null;
                    while (ll != place.latLng) {
                        ll = place.latLng;
                        Thread.sleep(1000);
                    }
                    Geocoder geocoder = new Geocoder(PlacePickerActivity.this);
                    List<Address> addresses = geocoder.getFromLocation(place.latLng.latitude,
                            place.latLng.longitude, 1);
                    if (addresses != null && !addresses.isEmpty()
                            && addresses.get(0).getMaxAddressLineIndex() > 0) {
                        Address address = addresses.get(0);
                        StringBuilder sb = new StringBuilder(address.getAddressLine(0));
                        for (int i = 1; i < address.getMaxAddressLineIndex(); ++i) {
                            if (i == 1 && sb.toString().equals(address.getFeatureName())) {
                                sb = new StringBuilder(address.getAddressLine(i));
                                continue;
                            }
                            sb.append(", ").append(address.getAddressLine(i));
                        }
                        if (place.latLng == ll) {
                            place.address = sb.toString();
                            place.name = address.getFeatureName();
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    updateInfoText();
                                }
                            });
                        }
                    }
                } catch (Exception ignored) {
                    Log.w(TAG, ignored);
                } finally {
                    geocoderInProgress.lazySet(false);
                }
            }
        }).start();
    }
}

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

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    int count = cursor.getCount();
    if (count == 0) {
        Context context = getActivity();
        CharSequence text = "No results found for your search.";
        int duration = Toast.LENGTH_LONG;
        Toast toast = Toast.makeText(context, text, duration);
        toast.show();//  ww  w . j av a2  s. co m
    } else {
        // Put the results on a map!
        GoogleMap googleMap = mMapView.getMap();
        double searchLocationDistanceM = 0;
        LatLngBounds.Builder boundsBuilder = new LatLngBounds.Builder();
        if (cursor.moveToFirst()) {
            // First, add the "searched for" location, if it was a location search.
            Location originLocation = new Location("");
            Address originAddress = sLocationQueryListener.getOriginAddress();
            if (originAddress != null) {
                // Get searched-for distance and convert to meters.
                short searchLocationDistance = sLocationQueryListener.getSearchLocationDistance();
                searchLocationDistanceM = searchLocationDistance * 1609.34;

                // Build up a list of Address1, Address2, Address3, if present.
                ArrayList<String> addressList = new ArrayList<String>();
                for (int i = 0; i <= 3; i++) {
                    String line = originAddress.getAddressLine(i);
                    if (line != null && line.length() > 0) {
                        addressList.add(line);
                    }
                }

                String addressDesc = TextUtils.join("\n", addressList);
                if (addressDesc == "") {
                    addressDesc = originAddress.getFeatureName();
                }
                if (addressDesc == "") {
                    addressDesc = "Searched Location";
                }

                // Create the LatLng and the map marker.
                LatLng originLatLng = new LatLng(originAddress.getLatitude(), originAddress.getLongitude());
                googleMap.addMarker(new MarkerOptions().position(originLatLng)
                        .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED))
                        .title(addressDesc));

                boundsBuilder.include(originLatLng); // In case only one result :)

                // Translate into a Location for distance comparison.
                originLocation.setLatitude(originAddress.getLatitude());
                originLocation.setLongitude(originAddress.getLongitude());
            } else {
                // Not a location search; don't add point for searched-for location
                // and don't check radius from that point.
                //Log.d(TAG, "Skipped adding origin address to map.");
            }

            // Next, add the results waterfalls.
            // Use do...while since we're already at the first result.
            do {
                // Get some data from the db
                Long waterfallId = cursor.getLong(AttrDatabase.COLUMNS.indexOf("_id"));
                double lat = cursor.getDouble(AttrDatabase.COLUMNS.indexOf("geo_lat"));
                double lon = cursor.getDouble(AttrDatabase.COLUMNS.indexOf("geo_lon"));

                // Make sure this one's actually within our search radius. SQL only checked
                // the bounding box.
                Location waterfallLocation = new Location("");
                waterfallLocation.setLatitude(lat);
                waterfallLocation.setLongitude(lon);

                if (originAddress == null
                        || (originLocation.distanceTo(waterfallLocation) <= searchLocationDistanceM)) {
                    // Not a location search (originAddress is null: show all) or within radius.
                    // Display on map.
                    String name = cursor.getString(AttrDatabase.COLUMNS.indexOf("name"));

                    LatLng waterfallLatLng = new LatLng(lat, lon);
                    Marker waterfallMarker = googleMap.addMarker(new MarkerOptions().position(waterfallLatLng)
                            .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE))
                            .title(name));

                    // Save the id so we can retrieve it when clicked
                    mMarkersToIds.put(waterfallMarker, waterfallId);
                    boundsBuilder.include(waterfallLatLng);
                }

            } while (cursor.moveToNext());

            // Zoom and center the map to bounds
            mResultBounds = boundsBuilder.build();
            zoomToBounds();
        }
    }
}