Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8854755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:57:24+00:00 2026-06-14T13:57:24+00:00

I have an app that reverse geocodes latitude & longitude into readable addresses. Here

  • 0

I have an app that reverse geocodes latitude & longitude into readable addresses. Here is a sample of the code below:

    protected List<Address> doInBackground(Double... params) {
            try {

                List<Address> addresses = geoCoder.getFromLocation(mylat,
                        mylong, 1);
                StringBuilder sBuilder = new StringBuilder();
                if (addresses.size() > 0) {
                    Address address = addresses.get(0);

                    for (int i = 0; i < address.getMaxAddressLineIndex(); i++) {
                        /**
                         * Returns a line of the address numbered by the
                         * given index (starting at 0), or null if no such
                         * line is present.
                         */
                        sBuilder.append(address.getAddressLine(i)).append(
                                "\n");
                        ////////////
                        ////////////
                        // sBuilder.append(address.getLocality()).append("\n");
                        //sBuilder.append(address.getPostalCode()).append("\n");        
                    }// end for
                    addressString = sBuilder.toString();

                }// end if
                return geoCoder.getFromLocation(params[0], params[1], 1);
            } catch (IOException e) {
                e.printStackTrace();
                return null;
            }// end catch
        }// end doInBackground method

I’d like to modify it so if the PostalCode is null, then print nothing, if it receives a value, display it wit hthe rest of the other details. The issue is I live in a country that do NOT use postal codes, which is why that part of the code is currently commented out. I’d like the app to display postal codes if you’re in a country that does use them (most do!) and ignore absence of one if you’re in my country or a similar one that do not use postal codes.

Can anyone recommend what change I need to make to allow this? I believe I need to add logic to deal with the appending of string here:

sBuilder.append(address.getPostalCode()).append("\n");

Thanks. 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T13:57:25+00:00Added an answer on June 14, 2026 at 1:57 pm

    I think you should just add one condition over there.

    if (address.getPostalCode() != null)
    {
        sBuilder.append(address.getPostalCode()).append("\n");
    }
    else
    {
        // do nothing.
    }
    

    Or is it not the thing you want?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am running into a very strange situation with an app I have that
I have a desktop app, that send e-mail, using remote smtp-server. So in code
The code below is from a Sinatra app (that uses DataMappe), which I am
We have an old legacy app that we need to reverse engineer how it
I have an android app that connects to the internet to do a reverse
have an app that finds your GPS location successfully, but I need to be
Have an app that has listings - think classified ads - and each listing
I have an app that switches between full screen and normal screen for a
I have an app that uses the ActionBar with tabs in combination with Fragments.
I have an app that lets the user interact with several forms. I can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.