Android uses location API to display address information implementation _android

Source: Internet
Author: User

This article illustrates the implementation of Android's address information display via the location API. Share to everyone for your reference. Specifically as follows:

The Android Locatin API allows you to display specific latitude and longitude address information through the Geocoder class. Such as:

By Geocoder Method Getfromlocation () can get the list of address objects. I only take one address result, I can take multiple, but it doesn't make much sense.

StringBuilder builder = new StringBuilder ();
Builder.append ("Northern Latitude:"). Append (This.location.getLatitude ()). Append ("\ n");
Builder.append ("N:"). Append (This.location.getLongitude ()). Append ("\ n");
try {
  list<address> addresses = new Geocoder (this). Getfromlocation (
      this.location.getLatitude (), This.location.getLongitude (),
      3);
  if (addresses.size () > 0) {Address
    = addresses.get (0);
    For [address address:addresses] {for
    (int i = 0; i < Address.getmaxaddresslineindex (); i++) {
      builder.a Ppend (Address.getaddressline (i)). Append ("\ n");
      Builder.append (Address.getlocality ()). Append ("\ n");
      Builder.append (Address.getpostalcode ()). Append ("\ n");
      Builder.append (Address.getcountryname ());
    }
    // }
  }

The effect is as shown in the following illustration:

I hope this article will help you with your Android program.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.