Example usage for android.location Address getLatitude

List of usage examples for android.location Address getLatitude

Introduction

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

Prototype

public double getLatitude() 

Source Link

Document

Returns the latitude of the address if known.

Usage

From source file:Main.java

public static Location getLocation(Address addr) {
    Location location = new Location(LocationManager.NETWORK_PROVIDER);
    location.setLatitude(addr.getLatitude());
    location.setLongitude(addr.getLongitude());
    return location;
}

From source file:com.kubotaku.android.openweathermap.lib.util.GeocodeUtil.java

/**
 * Get location address from target location name.
 * <p/>//from  w w w  .  j a  va  2 s .  c o m
 * Use Android Geocode class.
 * <p/>
 *
 * @param context Context.
 * @param locale  Locale.
 * @param name    Location name.
 * @return Location address.
 */
@Deprecated
public static LatLng nameToPoint(final Context context, final Locale locale, final String name) {
    LatLng address = null;

    try {
        Geocoder geocoder = new Geocoder(context, locale);
        List<Address> addressList = null;

        try {
            addressList = geocoder.getFromLocationName(name, 1);
        } catch (IOException e) {
            e.printStackTrace();
        }

        if ((addressList != null) && !addressList.isEmpty()) {
            for (Address point : addressList) {
                double latitude = point.getLatitude();
                double longitude = point.getLongitude();
                address = new LatLng(latitude, longitude);
            }
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

    return address;
}

From source file:fr.gotorennes.AbstractMapActivity.java

public static Location getLocation(Context context, String address) {
    if ("".equals(address.trim())) {
        android.location.Location l = LocationUtils.getLocation(context);
        return l != null
                ? new Location(l.getLatitude(), l.getLongitude(), context.getString(R.string.positionActuelle))
                : null;//from   www  .  j  av a 2s  . c om
    }

    Geocoder geocoder = new Geocoder(context);
    try {
        List<Address> addresses = geocoder.getFromLocationName(address + ",35 ille et vilaine", 1);
        if (addresses != null && !addresses.isEmpty()) {
            Address foundAddress = addresses.get(0);
            return new Location(foundAddress.getLatitude(), foundAddress.getLongitude(),
                    foundAddress.getAddressLine(0));
        }
    } catch (Exception ex) {
        Log.e("GoToRennes", ex.getMessage());
    }
    return null;
}

From source file:kien.activities.DistrictAcitivity.java

public LatLng getLocationFromAdress(String strAddress) {
    Geocoder geocoder = new Geocoder(this);
    List<Address> addresses;
    LatLng lng = new LatLng(0, 0);
    Log.e("LATLONG", "hello");
    try {/*w w  w  . j a  v a 2  s .c o m*/

        addresses = geocoder.getFromLocationName(strAddress, 5);
        Log.e("LATLONG", strAddress + "");
        if (addresses == null) {
            return null;
        }
        Address location = addresses.get(0);
        location.getLatitude();
        location.getLongitude();
        Log.e("LATLONG", location.getLatitude() + " " + location.getLongitude());
        lng = new LatLng(location.getLatitude(), location.getLongitude());
    } catch (IOException e) {
        Log.e("LATLONG", strAddress + " error");
        e.printStackTrace();
    }

    return lng;
}

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

private void setUpMap() {
    Intent intent = getIntent();/*from w  w w . j a va 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.sahana.geosmser.view.ReverseGeocoderView.java

public GeoPoint getGeoByDefaultAddress(String searchAddress) {
    GeoPoint mGeoPoint = null;//  w ww  .  j  a  v  a 2 s . c o m
    try {
        if (!searchAddress.equals("")) {
            Geocoder mGeocoder = new Geocoder(mContext, Locale.getDefault());
            List<Address> mAddressList = mGeocoder.getFromLocationName(searchAddress, 1);
            if (!mAddressList.isEmpty()) {
                Address mAddress = mAddressList.get(0);
                double mLatitude = mAddress.getLatitude() * 1E6;
                double mLongitude = mAddress.getLongitude() * 1E6;
                mGeoPoint = new GeoPoint((int) mLatitude, (int) mLongitude);
            } else {
                Log.d(WhereToMeet.TAG, "Address Not Found!");
            }
        }
    } catch (Exception e) {
        Log.d(com.sahana.geosmser.WhereToMeet.TAG, e.getMessage());
    }
    return mGeoPoint;
}

From source file:com.kpfunusa.RestaurantMap.java

public void get_latlng_zipcode() {
    try {/*ww w  .ja  va  2  s  .c  o m*/
        List<Address> addresses = geocoder.getFromLocationName(zip_code, 1);
        if (addresses != null && !addresses.isEmpty()) {
            Address address = addresses.get(0);
            // Use the address as needed
            String message = String.format("Latitude: %f, Longitude: %f",
                    restaurant_lat = address.getLatitude(), restaurant_lng = address.getLongitude());
            Toast.makeText(this, message, Toast.LENGTH_LONG).show();
        } else {
            // Display appropriate message when Geocoder services are not available
            Toast.makeText(this, "Unable to geocode zipcode", Toast.LENGTH_LONG).show();
        }
    } catch (IOException e) {
        // handle exception
    }
}

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

/**
 * Filters the addresses obtained in geocoding process, removing the
 * results outside server limits./* w  w  w.j  a v  a  2s.  co  m*/
 * 
 * @param the list of addresses to filter
 * @return a new list filtered
 */
private ArrayList<Address> filterAddressesBBox(ArrayList<Address> addresses) {
    if (!(addresses == null || addresses.isEmpty())) {
        ArrayList<Address> addressesFiltered = new ArrayList<Address>(addresses);

        for (Address address : addressesFiltered) {
            if (!LocationUtil.checkPointInBoundingBox(new LatLng(address.getLatitude(), address.getLongitude()),
                    selectedServer, OTPApp.CHECK_BOUNDS_ACCEPTABLE_ERROR)) {
                addressesFiltered.remove(address);
            }
        }

        return addressesFiltered;
    }
    return addresses;
}

From source file:com.capstone.transit.trans_it.TripDisplayActivity.java

public double[] getFromLocation(String address) {

    double[] Coordinates = new double[2];

    Geocoder geoCoder = new Geocoder(this, Locale.getDefault());
    try {//from  w w w. j  a  v  a 2  s. c  om
        Address addressConvert = geoCoder.getFromLocationName(address, 1).get(0);
        Coordinates[0] = addressConvert.getLatitude();
        Coordinates[1] = addressConvert.getLongitude();

    } catch (Exception ee) {

    }

    return Coordinates;
}

From source file:com.vishnuvalleru.travelweatheralertsystem.MainActivity.java

@SuppressLint("NewApi")
@Override//  w w w  .j a va  2  s . co  m
protected void onCreate(Bundle savedInstanceState) {
    Bundle b = getIntent().getExtras();
    String fromLocation = b.getString("from");
    String toLocation = b.getString("to");
    Geocoder coder = new Geocoder(this);
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);
    try {
        ArrayList<Address> frmAddresses = (ArrayList<Address>) coder.getFromLocationName(fromLocation, 50);
        ArrayList<Address> toAddresses = (ArrayList<Address>) coder.getFromLocationName(toLocation, 50);
        for (Address add : frmAddresses) {
            src_long = add.getLongitude();
            src_lat = add.getLatitude();
        }
        for (Address add : toAddresses) {
            dest_long = add.getLongitude();
            dest_lat = add.getLatitude();
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

    LatLng srcLatLng = new LatLng(src_lat, src_long);
    LatLng destLatLng = new LatLng(dest_lat, dest_long);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    FragmentManager myFragmentManager = getFragmentManager();
    MapFragment myMapFragment = (MapFragment) myFragmentManager.findFragmentById(R.id.map);

    myMap = myMapFragment.getMap();
    myMap.setInfoWindowAdapter(new PopupAdapter(getLayoutInflater()));
    myMap.setOnMapClickListener(new OnMapClickListener() {

        @Override
        public void onMapClick(LatLng point) {
            // Drawing marker on the map
            drawMarker(point);
        }
    });

    // Enabling MyLocation in Google Map
    myMap.setMyLocationEnabled(true);
    myMap.getUiSettings().setZoomControlsEnabled(true);
    myMap.getUiSettings().setCompassEnabled(true);
    myMap.getUiSettings().setMyLocationButtonEnabled(true);
    myMap.getUiSettings().setAllGesturesEnabled(true);
    myMap.setTrafficEnabled(true);
    myMap.animateCamera(CameraUpdateFactory.newLatLngZoom(destLatLng, 6));
    markerOptions = new MarkerOptions();

    drawMarker(srcLatLng);
    drawMarker(destLatLng);

    connectAsyncTask _connectAsyncTask = new connectAsyncTask();
    _connectAsyncTask.execute();
}