Android Address - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android Address class.

This code example shows how to use the following methods:setAddressLine, setAdminArea, setCountryCode, setLocality, setPostalCode
        this.lastLongitude = longitude;
        if (shouldSimulateGeocodeException) {
            throw new IOException("Simulated geocode exception");
        } 
        Address address = makeAddress();
        address.setAddressLine(0, addressLine1);
        address.setLocality(city);
        address.setAdminArea(state);
        address.setPostalCode(zip);
        address.setCountryCode(countryCode);
        return oneElementList(address);
    } 
 
    @Implementation 
    public List<Address> getFromLocationName(String locationName, int maxResults) throws IOException {
        didResolution = true;
        this.lastLocationName = locationName;
        if (shouldSimulateGeocodeException) {
            throw new IOException("Simulated geocode exception");
        } 

9
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:hasLatitude, hasLongitude
 
    @Test 
    public void setsUpHasLocationInAddressFromLocationName() throws Exception { 
        shadowOf(geocoder).setSimulatedHasLatLong(true, true);
        Address address = geocoder.getFromLocationName("731 Market St, San Francisco, CA 94103", 1).get(0);
        assertTrue(address.hasLatitude());
        assertTrue(address.hasLongitude());
        shadowOf(geocoder).setSimulatedHasLatLong(false, false);
        address = geocoder.getFromLocationName("731 Market St, San Francisco, CA 94103", 1).get(0);
        assertFalse(address.hasLatitude());
        assertFalse(address.hasLongitude());
    } 
 
    @Test 
    public void canReturnNoAddressesOnRequest() throws Exception { 
        shadowOf(geocoder).setReturnNoResults(true);
        List<Address> result = geocoder.getFromLocationName("731 Market St, San Francisco, CA 94103", 1);
        assertEquals(0, result.size());
    } 
 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setAddressLine, setAdminArea, setCountryCode, setLocality, setPostalCode
        this.lastLatitude = latitude;
        this.lastLongitude = longitude;
        if (shouldSimulateGeocodeException) {
            throw new IOException("Simulated geocode exception");
        } 
        Address address = new Address(Locale.getDefault());
        address.setAddressLine(0, addressLine1);
        address.setLocality(city);
        address.setAdminArea(state);
        address.setPostalCode(zip);
        address.setCountryCode(countryCode);
        return oneElementList(address);
    } 
 
    @Implementation 
    public List<Address> getFromLocationName(String locationName, int maxResults) throws IOException {
        this.lastLocationName = locationName;
        if (shouldSimulateGeocodeException) {
            throw new IOException("Simulated geocode exception");
        } 
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getAddressLine, getCountryName, getLocality, getMaxAddressLineIndex
            } 
            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",
                        address.getMaxAddressLineIndex() > 0 ? address.getAddressLine(0) : "",
                        address.getLocality(),
                        address.getCountryName());
                // Update address field on UI. 
                Message.obtain(mHandler, UPDATE_ADDRESS, addressText).sendToTarget();
            } 
            return null; 
        } 
    } 
 
    /** 
     * Dialog to prompt users to enable GPS on the device. 
     */ 
    private class EnableGpsDialogFragment extends DialogFragment {
 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getAddressLine, getAdminArea, getCountryName, getLatitude, getLocality
 
    @Override 
    public void onAddressAvailable(Address address) {
        Intent intent = new Intent(this, DetailsActivity.class);
        TagInfo tagsnap = new TagInfo();
        if (address.getMaxAddressLineIndex() > 0)
            tagsnap.setAddress1(address.getAddressLine(0));
 
        tagsnap.setAddress2(String.format("%s, %s, %s", address.getLocality(), address.getAdminArea(), address.getCountryName()));
        tagsnap.setLatitude(address.getLatitude());
        tagsnap.setLongitude(address.getLongitude());
        intent.putExtra("taginfo", tagsnap);
        startActivityForResult(intent, ADD_DETAILS_REQUEST);
    } 
 
    @Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == ADD_DETAILS_REQUEST) {
            if (resultCode == RESULT_OK) {
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getAdminArea, getCountryName, getLocality
      // We're only interested in a single address. 
      List<Address> addresses = coder.getFromLocation(mLatitude, mLongitude, 1);
      if (null != addresses && addresses.size() > 0) {
        Address addr = addresses.get(0);
 
        String locality = addr.getLocality();
        String admin = addr.getAdminArea();
        String country = addr.getCountryName();
 
        String descr = null;
        if (null != country) {
          descr = country;
          if (null != admin) {
            descr = String.format(Locale.US, "%s, %s", admin, descr);
          } 
          if (null != locality) {
            descr = String.format(Locale.US, "%s, %s", locality, descr);
          } 
          mDescription = descr;
        } 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getLatitude, getLongitude
	 
	public AddressOverlay(Address address) {
		super(); 
		assert(null != address);
		this.setAddress(address);
		Double convertedLongitude = address.getLongitude() * 1E6;
		Double convertedLatitude = address.getLatitude() * 1E6;
 
		setGeopoint(new GeoPoint( 
				convertedLatitude.intValue(),
				convertedLongitude.intValue()));
	} 
 
	@Override 
	public void draw(Canvas canvas, MapView mapView, boolean shadow) {
		super.draw(canvas, mapView, shadow);
    	Point locationPoint = new Point();
    	Projection projection = mapView.getProjection();
    	projection.toPixels(getGeopoint(), locationPoint);
    	Paint containerPaint = new Paint();
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getAddressLine, getAdminArea, getFeatureName, getLatitude, getLocality
        List<Address> addresses2 = g.getFromLocationName("San Francisco, CA", 1);
        assertNotNull(addresses2);
        assertEquals(1, addresses2.size());
 
        addr = addresses2.get(0);
        assertEquals("San Francisco", addr.getFeatureName());
        assertEquals("San Francisco, CA", addr.getAddressLine(0));
        assertEquals("United States", addr.getAddressLine(1));
        assertEquals("San Francisco", addr.getLocality());
        assertEquals("CA", addr.getAdminArea());
        assertEquals(null, addr.getPostalCode());
 
        assertFalse(Math.abs(addr.getLatitude() - 37.77916) > 0.1);
 
    } 
} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getAdminArea, getCountryName, getLatitude, getLocality, getLongitude
		return phisicalDirecction;
	} 
	 
	private DirectionDao getAddressDirection(Address address){
    	DirectionDao directionDao = new DirectionDao();
    		directionDao.setCountry(address.getCountryName());
    		directionDao.setPostalCode(address.getPostalCode());
    		directionDao.setArea(address.getAdminArea());
    		directionDao.setSubArea(address.getSubAdminArea());
    		directionDao.setLocality(address.getLocality());
    		directionDao.setStreet(address.getThoroughfare());
    		LocationDao locationDao = new LocationDao(address.getLongitude(), address.getLatitude());
    		directionDao.setLocation(locationDao);
    	return directionDao;
    } 
	 
	 
	private LocationDao getLocation(Address address){
    	return new LocationDao(address.getLongitude(), address.getLatitude());
    } 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getCountryName, getLocality
	 * @param address 
	 * @return 
	 */ 
	public String getSimpleLocation(Address address) {
		StringBuilder builder = new StringBuilder();
		String locality = address.getLocality();
		String countryName = address.getCountryName();
		 
		if(!StringUtils.isEmpty(locality)) {
			builder.append(locality);
		} 
		else if(!StringUtils.isEmpty(countryName)) {
			builder.append(countryName);
		} 
		 
		return builder.toString();
	} 
	 
} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Android Address Questions & Answers:

See Code Examples for Android Address Methods: