Geocoder getFromLocation - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Geocoder getFromLocation method.

This code example shows how to use the following methods:getFromLocation
  public static Address getAddress(final Context context,
      final Location location) {
    if (location == null)
      return null; 
 
    final Geocoder geocoder = new Geocoder(context);
    final List<Address> addresses;
    try { 
      addresses = geocoder.getFromLocation(location.getLatitude(),
          location.getLongitude(), 1);
    } catch (IOException e) {
      return null; 
    } 
    if (addresses != null && !addresses.isEmpty())
      return addresses.get(0);
    else 
      return null; 
  } 
} 
8
CodeRank
This code example shows how to use the following methods:getFromLocation
            mContext = context;
        } 
 
        @Override 
        protected Void doInBackground(Location... params) {
            Geocoder geocoder = new Geocoder(mContext, Locale.getDefault());
 
            Location loc = params[0];
            List<Address> addresses = null;
            try { 
                addresses = geocoder.getFromLocation(loc.getLatitude(), loc.getLongitude(), 1);
            } catch (IOException e) {
                e.printStackTrace();
                // Update address field with the exception. 
                Message.obtain(mHandler, UPDATE_ADDRESS, e.toString()).sendToTarget();
            } 
            if (addresses != null && addresses.size() > 0) {
                Address address = addresses.get(0);
                // Format the first line of address (if available), city, and country name. 
                String addressText = String.format("%s, %s, %s",
6
CodeRank
This code example shows how to use the following methods:getFromLocation
        mListener = listener;
    } 
 
    @Override 
    protected Void doInBackground(Location... locations) {
        Geocoder geocoder = new Geocoder(mContext, Locale.getDefault());
 
        Location loc = locations[0];
        List<Address> addresses = null;
        try { 
            // get all the addresses fro the given latitude, and longitude 
            addresses = geocoder.getFromLocation(loc.getLatitude(), loc.getLongitude(), 1);
        } catch (IOException e) {
            mAddress = null;
        } 
 
        // if we have at least one address, use it 
        if (addresses != null && addresses.size() > 0) {
            mAddress = addresses.get(0);
        } 
6
CodeRank
This code example shows how to use the following methods:getFromLocation, getFromLocationName
@Suppress 
public class GeocoderTest extends AndroidTestCase {
 
    public void testGeocoder() throws Exception { 
        Locale locale = new Locale("en", "us");
        Geocoder g = new Geocoder(mContext, locale);
 
        List<Address> addresses1 = g.getFromLocation(37.435067, -122.166767, 2);
        assertNotNull(addresses1);
        assertEquals(1, addresses1.size());
 
        Address addr = addresses1.get(0);
        assertEquals("94305", addr.getFeatureName());
        assertEquals("Palo Alto, CA 94305", addr.getAddressLine(0));
        assertEquals("USA", addr.getAddressLine(1));
        assertEquals("94305", addr.getPostalCode());
        assertFalse(Math.abs(addr.getLatitude() - 37.4240385) > 0.1);
 
        List<Address> addresses2 = g.getFromLocationName("San Francisco, CA", 1);
        assertNotNull(addresses2);

4
CodeRank
This code example shows how to use the following methods:getFromLocation
This code example shows how to use the following methods:getFromLocation
		geocoder = new Geocoder(context, Locale.getDefault());
	} 
	 
	public Address geoCode(double lat, double lng)  {
		try { 
			List<Address> fromLocation = geocoder.getFromLocation(lat, lng, 1);
			 
			if(fromLocation != null && fromLocation.size() > 0) {
				return fromLocation.get(0);
			} 
		} 
		catch (IOException e) {
			if(logger != null) {
				logger.error("Error geocoding location [" +
						lat +
						"," + 
						lng +
						"]", e);
			} 
			else { 
6
CodeRank
This code example shows how to use the following methods:getFromLocation
		if (!DataNetwork.hasDataConnection(ctx))
		{ 
			return null; 
		} 
 
		Geocoder myGeocoder = new Geocoder(ctx);
		Address address = null;
		try 
		{ 
			List<Address> list = myGeocoder.getFromLocation(
					loc.getLatitude(),
					loc.getLongitude(), 1);
	        if (list != null & list.size() > 0)
	        { 
	            address = list.get(0);
	        } 
		} 
		catch (Exception e)
		{ 
			Log.e(TAG, "Failed while retrieving nearest city");
6
CodeRank
This code example shows how to use the following methods:getFromLocation
	    int lng = (int) (loc.getLongitude() * 1E6);
	    return new GeoPoint(lat, lng);
	} 
	public static String createGeocoder(Context context,GeoPoint p){
		String address=null;
		Geocoder geocoder = new Geocoder(context, Locale.getDefault());
		List<Address> myList = null;
		try { 
			myList = geocoder.getFromLocation(p.getLatitudeE6()/1E6, p.getLongitudeE6()/1E6, 1);
		} catch (IOException e) {
			// TODO Auto-generated catch block 
			e.printStackTrace();
		} 
		if(myList!=null && myList.size()>0) {
	        address = new String();
	        address = myList.get(0).getAddressLine(0);
			} 
		return address;
	} 
	public static GeoPoint createGeoPoint(double lat, double lon) {
5
CodeRank
This code example shows how to use the following methods:getFromLocation
  public static Address getAddress(final Context context,
      final Location location) {
    if (location == null)
      return null; 
 
    final Geocoder geocoder = new Geocoder(context);
    final List<Address> addresses;
    try { 
      addresses = geocoder.getFromLocation(location.getLatitude(),
          location.getLongitude(), 1);
    } catch (IOException e) {
      return null; 
    } 
    if (addresses != null && !addresses.isEmpty())
      return addresses.get(0);
    else 
      return null; 
  } 
} 
6
CodeRank
This code example shows how to use the following methods:getFromLocation
	    int lng = (int) (loc.getLongitude() * 1E6);
	    return new GeoPoint(lat, lng);
	} 
	public static String createGeocoder(Context context,GeoPoint p){
		String address=null;
		Geocoder geocoder = new Geocoder(context, Locale.getDefault());
		List<Address> myList = null;
		try { 
			myList = geocoder.getFromLocation(p.getLatitudeE6()/1E6, p.getLongitudeE6()/1E6, 1);
		} catch (IOException e) {
			// TODO Auto-generated catch block 
			e.printStackTrace();
		} 
		if(myList!=null && myList.size()>0) {
	        address = new String();
	        address = myList.get(0).getAddressLine(0);
			} 
		return address;
	} 
	public static GeoPoint createGeoPoint(double lat, double lon) {
5
CodeRank

Related Geocoder getFromLocation Questions & Answers:

getFromLocation Method Overview
Returns an array of Addresses that are known to describe the area immediately surrounding the given latitude and longitude.
See Code Examples for other Android Geocoder Methods: